Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ClearAllManagedReferencesWithMissingTypes(Object)

Removes all managed references that are missing their type.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule
public static bool ClearAllManagedReferencesWithMissingTypes(Object obj)

Parameters

Returns

Type

Description

bool

Remarks

This method removes all serialized data associated with managed reference fields that have missing types.
This API is useful for removing missing type warning messages when an asset is loaded, for example if there is a reference to a class in a package that is not being used anymore.
This method returns false if the object had no references with missing types.

Examples

using System.Collections.Generic;using System.Text;using UnityEngine;using UnityEditor;public class ClearMissingTypeExample{ [MenuItem("Example/Clear ScriptableObject References with Missing Types")] static public void ClearMissingTypesOnScriptableObjects() { var report = new StringBuilder(); var guids = AssetDatabase.FindAssets("t:ScriptableObject", new[] {"Assets"}); foreach (string guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); Object obj = AssetDatabase.LoadMainAssetAtPath(path); if (obj != null) { if (SerializationUtility.ClearAllManagedReferencesWithMissingTypes(obj)) { report.Append("Cleared missing types from ").Append(path).AppendLine(); } else { report.Append("No missing types to clear on ").Append(path).AppendLine(); } } } Debug.Log(report.ToString()); }}