|
While trying to make a (rather complex) editor for a component, I decided that, instead of trying to cram everything into a custom inspector, to just make a simple one that creates a custom EditorWindow, like this: And use this window to edit the target. However, if the target is deleted and the window is still open, it should close itself. For that purpose I wrote the following at the start of the window's OnGUI(): However, if I test it out by simply not setting the target, I get the following errors: And the slightly more intuitive Am I doing something wrong? This seems to be all fine according to the Reference and the examples they've given.
(comments are locked)
|
|
Move that piece of code to the window's update function and you should be fine. Sorry for the late reply but won't this have a severe impact on performance? Not that it doesn't work...
Jul 12 '12 at 10:42 PM
crushy
No, the Update is only called when something changes. The Editor doesn't redraw itself 60 times per sec ;) only when it's necessary. An alternative could be to call GUIUtility.ExitGUI(); Which should terminate the current GUI redraw cycle. This should also be used in the inspector to avoid warnings. See But generally it's better to execute it from outside of OnGUI, or atleast in the repaint step. The same rule applies to changes to the GUI elements (adding / removing elements). Never change such a condition in the layout step. The layout and the repaint step have to be exactly the same.
Jul 12 '12 at 11:10 PM
Bunny83
(comments are locked)
|
|
What happens is that when target is not set, the first OnGUI call is used to close the window, which was generated in the same iteration. You basically need to change your window condition into something like: Even if I use that code or make sure it never closes the window on the first OnGUI call, I still get the same errors.
Jul 10 '12 at 06:20 PM
crushy
(comments are locked)
|
