# 6. Editor Window Pitfalls Part of [[Editor Windows with UI Toolkit]]. Prev: [[5. Worked Example Template Browser]]. ## Adding widgets in OnEnable `CreateGUI` is the official place to build the tree. Adding to `rootVisualElement` in `OnEnable` as well will duplicate controls every domain reload / re-enable. `root.Clear()` at the start of `CreateGUI` is a cheap guard. ## Touching widgets in Update before CreateGUI Official: `CreateGUI` might not run before the first `Update`. Null-check the labels you created there. ## Mixing OnGUI and CreateGUI for the same UI Pick UI Toolkit. Host leftovers in `IMGUIContainer` if you must ([[Custom Inspectors and Editor Tooling]]). ## Runtime PanelRenderer habits `EditorWindow.rootVisualElement` exists. Runtime 6000.5 `PanelRenderer` does **not** have `rootVisualElement` ([[3. Glyph Prompts in UI Toolkit]]). Do not copy a window into a player build and expect the same hookup. ## Mutations without Undo If Generate or a field write bypasses `SerializedObject` / `Undo`, designers will not forgive you. Dirty the asset (`EditorUtility.SetDirty`) after asset changes. ## Hard-coded asset paths that 404 silently Check `LoadAssetAtPath` results. Show a HelpBox / Label. ## Polling in Update Visible windows tick often. Prefer `Selection.selectionChanged` and serialized-object tracking. ## Editor scripts in a runtime assembly Keep window code under an `Editor` folder or an Editor-only assembly so a player build does not fail on `UnityEditor`. ## Sources - `CreateGUI` (6000.5): https://docs.unity3d.com/6000.5/Documentation/ScriptReference/EditorWindow.CreateGUI.html