unity OnInspector GUI вызов функции PrefabUtility.ReplacePrefab function Nullreference? - PullRequest
0 голосов
/ 04 августа 2020

Я вызываю PrefabUtility.ReplacePrefab в функции OnInspector GUI, но это ошибка. игровой объект - это выход. ошибка - NullReferenceException: ссылка на объект не установлена ​​для экземпляра объекта UnityEditor.InspectorWindow.GetEditorsWithPreviews (редакторы UnityEditor.Editor []) UnityEditor.InspectorWindow.DrawPreviewAndLabels ()

пожалуйста, как решить эту проблему? 1003 *

1 Ответ

0 голосов
/ 05 августа 2020

код:

public override void OnInspectorGUI()
{
            if (null == this.myTarget)
            {
                return;
            }
            PrefabType prefabType = PrefabUtility.GetPrefabType(mCurEditScene);
            if (prefabType == PrefabType.PrefabInstance ||
                prefabType == PrefabType.DisconnectedPrefabInstance)
            {
                GameObject rootUploadGameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(mCurEditScene.gameObject);
                var prefabParent = PrefabUtility.GetPrefabParent(rootUploadGameObject);
                PrefabUtility.ReplacePrefab(rootUploadGameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab);
            }
 }

ошибки:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.InspectorWindow.GetEditorsWithPreviews (UnityEditor.Editor[] editors)
UnityEditor.InspectorWindow.DrawPreviewAndLabels ()
UnityEditor.InspectorWindow.OnGUI ()
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) 
UnityEditor.HostView.Invoke (System.String methodName)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...