- Home /
Editor Script doesn't work on restart
I made a simple editor script to perform some operation on an object tree (i.e. set a value on a parent object and all its children). It works fine during use: I can make the window show, dock it, and use it. However, when I restart Unity after docking it I get:
Removed unparented EditorWindow while reading window layout: window #11, type=UnityEditor.FallbackEditorWindow, instanceID=13494 UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean)
followed by:
ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[UnityEditor.EditorWindow].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) UnityEditor.DockArea.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:328)
As I said the script works fine in the first instance; there are no compiler errors or warnings. Any idea?
Script:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class StampTool : EditorWindow {
public GameObject MaterialParent;
public Material material;
public GameObject ShadowsParent;
[MenuItem("Window/Stamp Tool")]
public static void ShowWindow() {
EditorWindow.GetWindow(typeof(StampTool), false, "Stamp Tool");
}
void OnGUI() {
GUILayout.Label("Stamp Material", EditorStyles.boldLabel);
MaterialParent = (GameObject) EditorGUILayout.ObjectField("Parent", MaterialParent, typeof(GameObject), true) as GameObject;
material = (Material) EditorGUILayout.ObjectField("Material", material, typeof(Material), true) as Material;
bool enabled = GUI.enabled;
GUI.enabled &= MaterialParent!= null && material != null;
if(GUILayout.Button("Stamp")) {
foreach(Renderer r in MaterialParent.GetComponentsInChildren<Renderer>()) {
r.material = material;
}
}
GUI.enabled = enabled;
EditorGUILayout.Separator();
GUILayout.Label("Stamp Receive Shadows", EditorStyles.boldLabel);
ShadowsParent = (GameObject)EditorGUILayout.ObjectField("Parent", ShadowsParent, typeof(GameObject), true) as GameObject;
enabled = GUI.enabled;
GUI.enabled &= ShadowsParent != null;
GUILayout.BeginHorizontal();
if(GUILayout.Button("Stamp On")) {
foreach(Renderer r in ShadowsParent.GetComponentsInChildren<Renderer>()) {
r.receiveShadows = true;
}
}
if(GUILayout.Button("Stamp Off")) {
foreach(Renderer r in ShadowsParent.GetComponentsInChildren<Renderer>()) {
r.receiveShadows = false;
}
}
GUILayout.EndHorizontal();
GUI.enabled = enabled;
}
}
Can you confirm this has nothing to do with the contents of OnGUI(), by remarking-out all that code temporarily, and testing it again? If you put this editorwindow in a new, otherwise empty, project, do you get the same error?
Same error after commenting out OnGui. I then made a new project and added that version (no OnGui) to it, and same error again :/
odd. Your ShowWinndow code looks almost identical to the documentation example. I'll test it on my system when I get back home: perhaps it's a system-specific problem.
Try to reset your Layout of the Unity editor (the drop down at the very top right of the editor). And default layout should do.
I'm not sure if the changed window title could cause a wrong recreation of the window. Try adding:
void OnEnable()
{
titleContent = new GUIContent("Stamp Tool");
}
I've copied your editor script as it is into my test project. I've tried several arrangements, different docking positions / states but not matter what i do the window loads back in just fine after a restart. Are you sure that there are no compiling errors whatsoever? Any compiling error in another script could prevent the loading of your editor window class at startup.
What you could try is:
closing your custom editor window.
close Unity
delete the metadata file of your editor window script
restart Unity
If the problem persists there must be something else wrong. In that case it would be great to know:
your exact OS version
your exact Unity version
where and how that editor window is docked (maybe a screenshot)
Hi, I just meet the same problem. So have you resolved this error?
No, I pretty much just gave up on it. it only has a problem when I dock it, so now I just open the tools window when I need to use it then close it after :/
Your answer
Follow this Question
Related Questions
Undo.Record: Recording variables within array elements 0 Answers
How can I create a custom AssetPreview for a prefab 1 Answer
layout serializable objects in unity 1 Answer
Drag from custom editor ObjectField 0 Answers
How Mark Prefab Dirty? 1 Answer