Agustin0987
Agustin0987

Reputation: 601

Unity - Create EditorWindow with editor block functionality (like EditorUtility.DisplayDialog)

Like the title says, I would like to create a custom EditorWindow that will block the Unity Editor in the same way as the EditorUtility.DisplayDialog does. I know how to create an EditorWindow, what I don't know how to do, is how to block the Editor until the user press a button in my custom EditorWindow or the window gets closed.

If anyone has an idea on how to approach this, I would really appreciate the help. Thanks.

Upvotes: 1

Views: 1993

Answers (1)

derHugo
derHugo

Reputation: 90704

Currently afaik there seems to be no way to archive this with a custom EditorWindow.


You can could have used ShowModalUtility for this (introduced in 2019.1).

Simply in the line where you would usually do e.g.

yourWindow.Show();

replace it by using instead

yourWindow.ShowModalUtility();

Show the EditorWindow as a floating modal window.

The utility window does not allow interaction with the editor while running. This means the EditorWindow.ShowModalUtility window is never hidden by the Unity editor. It is, however, notdockable to the editor.

Utility windows will always be in front of normal Unity windows. It will be hidden whenthe user switches from Unity to another application.

Note: You do not need to use EditorWindow.GetWindow before using this function to show the window.


BUT Just noted: Usually this should do the trick but unfortunately there seems to be a bug still existing since Unity 2019.1 was in alpha status .. apparently it wasn't fixed until now ...

As you can see in the linked bug report they say it has too low priority and pushed the possible fix to Unity 2019.3 .. which currently is still in alpha state .. so ... who knows if and when this will be actually fixed


Little fun fact: In the linked example code Unity has it wrong and used ShowUtility instead of ShowModalUtility

Upvotes: 1

Related Questions