Unity Issue Tracker - NullReferenceException is thrown when opening a custom UI Toolkit Editor Window
Closed
UUM-60620
NullReferenceException is thrown when opening a custom UI Toolkit Editor Window
Unity: UI Toolkit Framework
As Designed
2023.3.X
2023.2.X
2022.3.X
2021.3.X
The NullReferenceException occurs because no VisualTreeAsset was assigned on the MyCustomEditor script. To fix it, click the MyCustomEditor.cs asset in the Project Window, and assign a VisualTreeAsset to the field in the Inspector Window.
Reproduction steps:
1. Open the attached “Repro“ project
2. Open the Custom Editor Window (Window > UI Toolkit > MyCustomEditor)
3. Observe the Window and Console
Expected result: No errors/logs are present and there's a Button and a Toggle in the MyCustomEditor Window
Actual result: NullReferenceException is thrown and there are no Button or Toggles seen in the MyCustomEditor Window