Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved EditorWindow "Failed to load" after entering and exiting play mode

Discussion in 'Scripting' started by Rowlan, Sep 25, 2023.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,810
    I just spent the better part of the hour trying to find out why my editor window wouldn't load after entering and exiting play mode.

    Basically before play mode:

    before.png
    After exiting play mode:

    after.png

    Long story short: The class name and the filename must match. In my case I had just a typo during refactoring.

    Repro case:

    create file
    Code (csharp):
    1. MyBrokenEditorWindow.cs
    with content

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class TestMyBrokenEditorWindow : EditorWindow
    5. {
    6.     [MenuItem("Window/Test/MyBrokenEditorWindow")]
    7.     public static void CreateWindow()
    8.     {
    9.         TestMyBrokenEditorWindow wnd = GetWindow<TestMyBrokenEditorWindow>();
    10.         wnd.titleContent = new GUIContent("TestMyBrokenEditorWindow");
    11.     }
    12.  
    13. }
    Open the window via menu, dock it anywhere. Enter and exit play mode with Maximized window setting and the problem will occur.

    I searched here on the forum, but didn't find a solution. I thought I'd share before anyone else wastes their time with the same problem.

    Unity version I have this is 2021.3.27. Seems to be solved somewhere between this and 2023.0.2.b7 which is the other version I tested in order to file a bug report.
     
    Last edited: Sep 25, 2023
  2. tomfulghum

    tomfulghum

    Joined:
    May 8, 2017
    Posts:
    69
    Doesn't seem like a bug to me. EditorWindow inherits from ScriptableObject, and ScriptableObject class names must match the name of the script file they're defined in, just like for MonoBehaviour.
     
  3. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,810
    It's a bug. It was fixed