Ivan Cavalheiro
Ivan Cavalheiro

Reputation: 109

EditorWindow.GetWindow doesn't work

This is my code:

public class CrazyWindow: EditorWindow 
{
    [MenuItem("Window/CrazyWindow")]
    public static void Window()
    {
        EditorWindow.GetWindow(typeof(CrazyWindow));

        Debug.Log("It should have appeared!");
    }

    string test = "";
    public void OnGUI()
    {
        test = EditorGUILayout.TextField ("Text Field", test );
    }
}

I'm using Unity3D v. 4.3.4f1 (free version) on Windows 7. I have no idea why this is happening, as I can see in tutorials in the internet, that's how it should be done. The script is also in the Editor folder.

I'm able to click on the option "CrazyWindow" in the window menu, and I also get the Debug message informing me that the window should be working, but nothing happens besides that. No window is created at all!

What might be the cause of my problem?

Upvotes: 1

Views: 2698

Answers (3)

Atiq Ur Rehman Qazi
Atiq Ur Rehman Qazi

Reputation: 3

As Bart said, it remembers useless things
Just make it remember what we want it to

private void OnLostFocus() {
    GetWindow<CrazyWindow>().Close();
}

Upvotes: 0

Ivan Cavalheiro
Ivan Cavalheiro

Reputation: 109

Problem solved.

As Bart mentioned, I was using a custom Editor Layout, which was the case for the window not showing.

I just switched to one of the factory editor layouts and: ta dah, the window was there...

Pretty buggy thought.

Upvotes: 4

user3576026
user3576026

Reputation:

Try renaming the 'CrazyWindow' part in the MenuItem and of the class itself. Unity remembers whether a window is visible or not and somehow something goes wrong there. Probably it thinks your window is visible (in cache) while actually it is not.

Upvotes: 1

Related Questions