[C#] Custom EditorWindow fails to load whenever a compiler error happens [Solved]

So I am working on a custom EditorWindow widget that shows info and things.

When I am writing code, write a little typo somewhere, and compile, the compiler outputs an error and prevents me from building my game just as everyone would expect.

However, that custom little EditorWindow also won’t compile correctly even though its code is fine and the window will become empty and have the title “Window failed to load”. How can I fix that?

I use Build Report and that doesn’t break when my game doesn’t compile. Neither does ConsoleEnhanced or Script Inspector 3. How do their script files completely avoid being recompiled?

ConsoleEnhanced uses a dll so that is probably why it isn’t affected. But Build Report and Script Inspector 3 don’t so how do they do it?

Sorry for the bump. Does anybody have any ideas?

Sorry for the second bump. Does anyone have any ideas? I would really appreciate any help on this.

Why don’t you ask @Flipbookee (author of Script Inspector 3)? I’ve always found him to be very friendly and helpful.

1 Like

Well it could use the broken code in some way. Try something neutral that clearly will not use any of your code.
Maybe an example from unity documentation:

//C# Example
using UnityEditor;
using UnityEngine;

public class MyWindow : EditorWindow
{
    string myString = "Hello World";
    bool groupEnabled;
    bool myBool = true;
    float myFloat = 1.23f;
   
    // Add menu item named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    public static void ShowWindow()
    {
        //Show existing window instance. If one doesn't exist, make one.
        EditorWindow.GetWindow(typeof(MyWindow));
    }
   
    void OnGUI()
    {
        GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
        myString = EditorGUILayout.TextField ("Text Field", myString);
       
        groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
            myBool = EditorGUILayout.Toggle ("Toggle", myBool);
            myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
        EditorGUILayout.EndToggleGroup ();
    }
}
1 Like

Thanks,

I can’t test it right now, but I don’t think it has anything to do with any code I wrote incorrectly. Hotbar(free asset) Unity Asset Store - The Best Assets for Game Making has the same problem. If any compiler error happens it will break too.

Contacting @Flipbookee is a good idea, i didn’t even think of asking him personally.

Dunno if this would work but have you tried putting it in a Plugins/Editor folder

I tried hotbar. Nothing really breaks. Even if I add a broken script to the hotbar.
I also tried to add a prefab using that broken script to the hotbar.
Try a new project with MyWindow scrit. It could be something related to your current project or even to Unity Editor version that you have.

Yes it’s in an editor folder. And the MyWindow script breaks too.

Reproducing this is quite simple. create a new empty project, create an editor folder, create the MyWindow script inside the editor folder. Create a NewBehaviorScript outside the editor folder. Then open a MyWindow using Window/My_Window, and place it somewhere in the editor. Finally, type some random stuff in the NewBehaviorScript, go back into the editor, and the MyWindow you placed earlier will dissapear because of the error.

Unity version then.
5.4.0f3 x64 - works fine.

1 Like

There was a bug introduced in Unity 5.3.4 patch 4 that broke recognition of compile errors from the compiler output, so Unity Editor was trying to reload the assemblies even when the code didn’t compile successfully, resulting with missing code for custom editor windows.

Unfortunately the bug was inherited to all later patch releases and also to version 5.3.5f1 and its patch releases 1 to 5. It was fixed in 5.3.5 patch 6 :slight_smile: finally, and 5.4.0 didn’t get affected by the bug :sunglasses:

1 Like

@zaxvax I have v5.3.5f1… so is this only a bug with the version I’m working with?

@Flipbookee That explains it. But then how come Script inspector stays open and usable when some other editorwindows do not with this bug? Did you do anything special so the scripts wouldn’t be recompiled?
P.S. Your assets are great, keep up the good work :slight_smile:

1 Like

@Flipbookee So how did you do it?

No, I didn’t do anything special. The only thing different is that Si3 gets compiled in the first-pass assemblies, so only a compile error in those scripts can break the Si3 code.

I tried to find a workaround for that bug in Unity with no success. A bit later I realized there’s no point to do that because those are broken and unusable versions of Unity! Every programmer knows that running partially compiled code is dangerous for the data that code operates on, and this is not an exception. Using any of those broken Unity releases is very dangerous for the projects! There’s no point in trying to make a broken Unity to work with custom windows when it’s so broken that it will mess up the whole project. It messes up even its own data, such as the layout of the editor - once you upgrade the project to at least Unity 5.3.5 patch 6 you should reset the layout to “fix” that.

Yes, the fix is in 5.3.5p6 :slight_smile:

1 Like

@Flipbookee (and friends) Thank you so much for the help :), I’ll update and see how well everything works. Will mark thread as solved.