1

So I am creating an editor tool, this tool is open by clicking in a custom MenuItem. This tool is open as a utility window using the GetWindow<T>(true, "title") and ShowModalUtility() methods. This new utility window has button that will open another utility window (different editor window type) using the same methods mentioned above.

I don't know if is a bug or by design, but it seems like having multiple utility windows open is not working properly. When the second utility window is open (by pressing the button in the first one) the rest of the unity editor is still block like it should, but the second utility window does not block the first one.

It looks as if being a utility window is a "static" thing and all utility windows have the same priority so you can click on any of them at any time.

Does anyone know how to block one utility editor window using another utility editor window?

P.S: I saw this post, and like I mentioned, I am using ShowModalUtility() but it does not work properly for me, when I have both utility windows open.

UPDATE:

Here is a working example:

using UnityEditor;
using UnityEngine;

public class Test
{
    public class TestWindow1 : EditorWindow
    {
        [MenuItem("TEST/Test Window 1")]
        public static void Open()
        {
            var window = GetWindow<TestWindow1>(true, "Test Window 1");
            window.ShowModalUtility();
        }

        private string text = "";

        void OnGUI()
        {
            text = EditorGUILayout.TextField("Try To Write Here:", text);
            if (GUILayout.Button("Open Test Window 2"))
            {
                TestWindow2.Open();
            }
        }
    }

    public class TestWindow2 : EditorWindow
    {
        public static void Open()
        {
            var window = GetWindow<TestWindow2>(true, "Test Window 2");
            window.ShowModalUtility();
        }

        private string text = "";

        void OnGUI()
        {
            text = EditorGUILayout.TextField("Try To Write Here:", text);
            if (GUILayout.Button("Open Test Window 3"))
            {
                TestWindow3.Open();
            }
        }
    }

    public class TestWindow3 : EditorWindow
    {
        public static void Open()
        {
            var window = GetWindow<TestWindow3>(true, "Test Window 3");
            window.ShowModalUtility();
        }
 
        void OnGUI()
        {
            EditorGUILayout.LabelField("NOTHING TO DO HERE!!!!");
        }
    }
}

So if you try to run this code then: You will open TestWindow1, if you try to write something in there it will work and if you try to click on the editor it will be block (this is correct behaviour).

If then you open TestWindow2 you should be able to write in window 2 but you should not be able to write in window 1 (window 1 should be block by window 2) here is the problem: At the moment of writing this update, I am able to write in window 1 even when window 2 is open, and also I can write in both window 1 and 2 when window 3 is open, in other words, the utility windows don't block each other, they only block the editor.

Agustin0987
  • 581
  • 6
  • 15

1 Answers1

0

Test environment: Unity 2021.3.15f1 (SILICON for mac)

In my environment, TestWindow2 is not displayed until TestWindow1 is closed. In my environment, it seems that there is only one Window that can be opened with ShowModalUtility().

enter image description here

I think the easiest way to display multiple windows is to check the flags and pass them to EditorGUI.BeginDisabledGroup. However, in that case, ShowModalUtility() cannot be used.

enter image description here

public class Test
{
    public class TestWindow1 : EditorWindow
    {
        public static bool IsOpen { get; private set; }
        
        [MenuItem("TEST/Test Window 1")]
        public static void Open()
        {
            var window = GetWindow<TestWindow1>(true, "Test Window 1");
            window.Show();
        }

        private string text = "";

        void Awake() => IsOpen = true;
        
        void OnGUI()
        {
            EditorGUI.BeginDisabledGroup(TestWindow2.IsOpen || TestWindow3.IsOpen);
            text = EditorGUILayout.TextField("Try To Write Here:", text);
            if (GUILayout.Button("Open Test Window 2"))
            {
                TestWindow2.Open();
            }
            EditorGUI.EndDisabledGroup();
        }
        
        void OnDestroy() => IsOpen = false;
    }

    public class TestWindow2 : EditorWindow
    {
        public static bool IsOpen { get; private set; }
        
        public static void Open()
        {
            var window = GetWindow<TestWindow2>(true, "Test Window 2");
            window.Show();
        }

        private string text = "";

        void Awake() => IsOpen = true;

        void OnGUI()
        {
            if (!TestWindow1.IsOpen)
            {
                Close();
            }
            
            EditorGUI.BeginDisabledGroup(TestWindow3.IsOpen);
            text = EditorGUILayout.TextField("Try To Write Here:", text);
            if (GUILayout.Button("Open Test Window 3"))
            {
                TestWindow3.Open();
            }
            EditorGUI.EndDisabledGroup();
        }

        void OnDestroy() => IsOpen = false;
    }

    public class TestWindow3 : EditorWindow
    {
        public static bool IsOpen { get; private set; }
        
        public static void Open()
        {
            var window = GetWindow<TestWindow3>(true, "Test Window 3");
            window.Show();
        }
 
        void Awake() => IsOpen = true;
        
        void OnGUI()
        {
            if (!TestWindow1.IsOpen || !TestWindow2.IsOpen)
            {
                Close();
            }
            
            EditorGUILayout.LabelField("NOTHING TO DO HERE!!!!");
        }
        
        void OnDestroy() => IsOpen = false;
    }
}

Considering the function of ShowModalUtility(), I do not feel uncomfortable with the specification that only one window can be opened. So I think it is better to use the above method or complete within one Window.

Past Responses: -------------------

Could you please provide a minimum reproduction code? Then I may be able to help.

Below is my test code:

enter image description here

using UnityEditor;
using UnityEngine;

// TestWindow1.cs
public class TestWindow1 : EditorWindow
{
    [MenuItem("Test/Window1")]
    static void ShowWindow()
    {
        var window = GetWindow<TestWindow1>();
        window.ShowModalUtility();
    }

    void OnGUI()
    {
        if (GUILayout.Button("Open Window2"))
        {
            var window = GetWindow<TestWindow2>();
            window.ShowModalUtility();
        }
    }
}

// TestWindow2.cs
public class TestWindow2 : EditorWindow
{
    void OnGUI()
    {
        if (GUILayout.Button("Open Window3"))
        {
            var window = GetWindow<TestWindow3>();
            window.ShowModalUtility();
        }
    }
}

// TestWindow3.cs
public class TestWindow3 : EditorWindow {}
IShix
  • 186
  • 7
  • Actually your example seems to be a perfect match to what I'm describing, the only thing your code is missing (to be exactly like mine) is to pass "true" as first argument to the GetWindow method (although the "true" argument makes no diference, since I already tried without it). Btw, you GIF is kind of fast, so i can't see if it is working for you or not. Is it? – Agustin0987 Dec 18 '22 at 06:49
  • The behavior of this test code is that the third window(`TestWindow3`) remains black and does not display its contents until the second window(`TestWindow2`) is closed. This code does not allow you to touch more than one Window. – IShix Dec 18 '22 at 07:53
  • The gif is the result of executing this test code. – IShix Dec 18 '22 at 07:53
  • But in your GIF you press the menu item and open TestWindow1, then you press the TestWindow1 button to open TestWindow2, and TestWindow2 remains black and you can interact with it. I don't see TestWindow3 in the GIF, and also TestWindow3 has no content (empty class) si it should display nothing, if it does show up. Maybe I am missing something on your test? I will provide an example, as soon as Ican. – Agustin0987 Dec 18 '22 at 17:13
  • In my code, I cannot click the button to open `TestWindow3` because the contents of `TestWindow2` are black and not displayed. I need your minimum configuration test code that can reproduce the problem. Please do so. – IShix Dec 19 '22 at 05:20
  • I posted a code that shows my problem (and more precise explanation), also I noticed that you are working on Apple, so maybe this issue might be Windows specific. – Agustin0987 Dec 19 '22 at 16:58
  • Please see the information I have added to my answer. Could you also tell us what version of Unity you are using? This is a very interesting behavior. – IShix Dec 20 '22 at 06:20
  • Yes I see your behaviour, and I must say at least you get one window focused at a time, even if it is inverted (in theory Window 2 should take priority over Window 1) mine is just like I described originally. I have tested this in both Windows 10 and 11, and in Unity 2021.1.13f – Agustin0987 Dec 23 '22 at 05:44