モデルを変更するためのかなり複雑なUnity Editorスクリプトがあります。これは、アセットフォルダに新しいオブジェクトを作成し、インスペクタでモデル、いくつかの修飾子を適用して適用することによって使用されます。これにより、モデルが変更され、作成されたオブジェクトが新しいオブジェクトプレハブに置き換えられます。UnityEditor.InspectorWindow.GetEditorsWithPreviewsからのNullReferenceException
適用押すと、方法Apply()
が呼び出され、それが実行された後、このうちコンソールプリント:
とNullReferenceException:オブジェクト参照が オブジェクトのインスタンスUnityEditor.InspectorWindow.GetEditorsWithPreviews に設定されていません( Cで:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:515)(UnityEditor.Editor []エディタ) UnityEditor.InspectorWindow.DrawPreviewAndLabels()( Cで:/ buildslave /ユニティ/ビルド/エディタ/モノ/インスペクタ/ InspectorWindow.cs:612) UnityEditor.InspectorWインテル.OnGUI()( でC:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:398) System.Reflection.MonoMethod.Invoke(System.Object obj、BindingFlags invokeAttr、System.Reflection .Binderバインダー、System.Object [] パラメーター、System.Globalization.CultureInfo culture)( /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) TargetInvocationExceptionとして再スローします。呼び出しの ターゲットによって例外がスローされました。 System.Reflection.MonoMethod.Invoke /ユーザ/ builduser/buildslave/AT(System.ObjectのOBJ、のBindingFlags invokeAttr、System.Reflection.Binder バインダー、System.Objectの[]パラメータ、可能System.Globalization.CultureInfo 培養)( (System.Object obj、 System.Object [] parameters)( /Users/builduser/obj/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232) System.Reflection.MethodBase.Invoke (buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView.Invoke(System.String methodName、System.Object obj)(C:/ buildslave/unity/build /Editor/Mono/HostView.cs:272) UnityEditor.HostView.Invoke(System.String methodName)()C:/buildslave/unity/build/Editor/Mono/HostView.cs:265) UnityEditor.HostView.InvokeOnGUI(Rect onGUIPosition)( C:/buildslave/unity/build/Editor/Mono/HostView.cs: 232)
2014年から同様のエラーで、さまざまな状況で質問が見つかりました。回答はありませんhere。
例外が発生する可能性があるためにMattRix's decompiled Unity repoを確認しました。レポのバージョンが2017.1.0f3で2017.1.1f1になっていても、問題が発生した場所が見つかりました。 DrawPreviewsAndLabels()
で :
IPreviewable[] editorsWithPreviews = this.GetEditorsWithPreviews(this.tracker.activeEditors);
そして
GetEditorsWithPreviews(Editor[] editors){
...
for (int i = 0; i < editors.Length; i++)
{
Editor editor = editors[i];
...
例外がラインEditor editor = editors[i];
に呼び出されているように見えます。これにより、this.tracker.activeEditors
は、要素がnull
のリストであると考えられます。これは私が立ち往生している場所です。
これは何を引き起こす可能性があると私は何ができるのか、このエラーを修正するためにチェック?
EDIT:this.tracker.activeEditors
自体がnullである可能性があります。その場合、例外はeditors.Length
で発生し、少なくともforループには入るべきではないと思います。 Unityバージョンの変更で行番号が変更された可能性があるので、そのコード内の行は実際に例外の原因ではないかもしれませんが、私はそれを知る方法がありません。
このnullpointerを簡単に修正できないという問題は、コードからの呼び出しがなくてもエディタコードで発生し、何をするべきかわからないということです。this.tracker.activeEditors
またはその原因が何であれ、正しく配置する必要がありますさあ。
アクティブな編集者がいるように、何かをアクティブにする必要がありますか?
これは私のApply()
方法である:OnInspectorGUI()
がオブジェクトを交換した後に何かをしようとしているときにエラーが表示されるかもしれないと思わ
public IPreviewable[] GetEditorsWithPreviews(Editor[] editors)
{
IList<IPreviewable> list = new List<IPreviewable>();
int num = -1;
for (int i = 0; i < editors.Length; i++)
{
Editor editor = editors[i];
num++;
if (!(editor.target == null))
{
if (!EditorUtility.IsPersistent(editor.target) || !(AssetDatabase.GetAssetPath(editor.target) != AssetDatabase.GetAssetPath(editors[0].target)))
{
if (EditorUtility.IsPersistent(editors[0].target) || !EditorUtility.IsPersistent(editor.target))
{
if (!this.ShouldCullEditor(editors, num))
{
if (!(editors[0] is AssetImporterEditor) || editor is AssetImporterEditor)
{
if (editor.HasPreviewGUI())
{
list.Add(editor);
}
}
}
}
}
}
}
foreach (IPreviewable current in this.m_Previews)
{
if (current.HasPreviewGUI())
{
list.Add(current);
}
}
return list.ToArray<IPreviewable>();
}
と ')('Applyに
を交換することによって解決されるようになし、むしろ 'this.tracker.activeEditors'がヌルであることを意味します。 –
これをどうやって修正しますか?それは私のコードではなくUnityEditorのものなので、直接アクセスすることはできません。割り当てが必要な場所を追跡することはできません。私が知る限り自分で割り当てることはできません。 –
さて、申し訳ありませんが、それを知らなかった。だから私はあなたの質問を再開しました。私は統一されていないので、残念ながら私はあなたの問題を解決することはできません。 –