Version: 2022.1
LanguageEnglish
  • C#

SerializationUtility.ClearAllManagedReferencesWithMissingTypes

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool ClearAllManagedReferencesWithMissingTypes(Object obj);

Description

Removes all managed references that are missing their type.

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.

See Also: ClearManagedReferenceWithMissingType, SerializeReference.

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()); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961