- Home /
Opening a EditorWindow via Inspector == Error?
Hey there..
I´ve created a greater EditorWindow, which should be the AllInOne Editor for 4-5 Scripts of my Scene Setup Object.
So now, every of these 4-5 Scripts will get such an Inspector override attached:
[CustomEditor(typeof(Sys_Vocab))]
public class Sys_VocabEditor : Editor
{
public override void OnInspectorGUI()
{
if(GUILayout.Button("Open Vocab Editor")){
File.WriteAllText("crml.dat", (2).ToString());
EditorWindow.GetWindowWithRect(typeof(Editor_Scene_Setup), new Rect(0, 0, 800, Screen.height));
GUIUtility.ExitGUI();
}
}
}
This should open the EditorWindow, and show the Script depending Stuff by asking what ID "private int EditorFenster;" is set to.
EditorFenster is set by reading out "crml.dat", which is filled with only the ID integer by the Inspector overrides.
The Problem: If i open the EditorWindow via my Topmenü Setting (GameObject > Create Other > Scene_Setup), everything runs fine! When clicking the Button in the Inspector, i get this:
Any idea what could be wrong here, and how to solve that Error Stuff?
TESTPROJECT TO REPRODUCE THE PROBLEM: link text
The error you have highlighted in the screenshot happens on line 285 and is most likely caused by the NullReferenceException error on line 281 of the Editor_Scene_Setup script. Do you know how to debug code using $$anonymous$$onoDevelop?
yes But the object in that line isn't null, cause i'm checking for that in that line..
And the highlighted error doesn't appear when calling the window from GameObject > Create Other > Scene_Setup
Both Errors only appear when calling the Window from the custom Inspectors..
try resetting the window layouts. might have something to do with this. some layouts in unity pop up with errors.
same error with default layout, game layout or any of the other window layouts..
Answer by Vurawid · Dec 13, 2014 at 06:33 AM
The error has to do with trying to show the Vocabs section right away in the EditorWindow. It is a simple enough fix. Setup the code to run through OnGUI 2 or 3 times in Editor_Scene_Setup with EditorFenster=0 prior to reading from the crml.dat file. I tested it out and the errors went away in the test project by doing this.
Updated now that I have time to share more details... here are changes I made. Also improved upon the original solution I did.
Removed this section of code from OnGUI:
if (File.Exists("crml.dat")) { ... }
private bool m_IsInitialized = false; private Nullable m_StartingEditorFenster = null; public void SetStartEditorFenster(int editorFenster) { m_IsInitialized = false; m_StartingEditorFenster = editorFenster; }
if (m_IsInitialized == true) { if (m_StartingEditorFenster.HasValue) { EditorFenster = m_StartingEditorFenster.Value; m_StartingEditorFenster = null; } } m_IsInitialized = true;
Changed the code in Sys_VocabEditor. Note something similar needs to be done for Sys_LanguageEditor...
public override void OnInspectorGUI() { if(GUILayout.Button("Open Vocab Editor")){ Editor_Scene_Setup thisWindow = (Editor_Scene_Setup)EditorWindow.GetWindowWithRect(typeof(Editor_Scene_Setup), new Rect(0, 0, 800, Screen.height)); thisWindow.SetStartEditorFenster (2); GUIUtility.ExitGUI(); } }
O$$anonymous$$AY...
I managed to get rid of the NullReference..
But the "ArgumentException" Error is still appearing.
Answer by Chaosgod_Esper · Dec 15, 2014 at 08:01 AM
OKAY
Found a Solution for the ArgumentException Error. I needed to place the File Reader as last step in OnGUI, so OnGUI runs first with EditorFenster as 0, and sets itself via File readout to the new value.
Your answer
Follow this Question
Related Questions
Android Build Error,Android Gradle Build Error 1 Answer
"The name does not exist in the current context" error 1 Answer
HELP! is this a Bug in the game engine? 1 Answer
Use of the inspector along with a custom editorwindow 1 Answer
How do I prevent an error when opening a scene from an EditorWindow? 0 Answers