Hi, I’m trying to open a custom EditorWindow as a modal, but calling ShowModal() from a GenericMenu item’s callback makes the window appearing full white with no visible content.
Any idea on how to work around this?
Here is an example for reproducing the bug, just add this script to a GameObject to reproduce:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class CustomModal : EditorWindow
{
public static void Open()
{
CustomModal win = GetWindow<CustomModal>();
win.ShowModal();
}
private void OnGUI()
{
EditorGUILayout.LabelField("I'm a modal");
}
}
[CustomEditor(typeof(IssueDemo))]
public class IssueDemoEditor : Editor
{
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("OPENING MODAL THROUGH REGULAR BUTTON IS WORKING");
if (GUILayout.Button("Regular Button"))
{
CustomModal.Open();
}
EditorGUILayout.LabelField("OPENING MODAL THROUGH GENERIC MENU IS NOT WORKING (all white)");
if (GUILayout.Button("Generic Menu"))
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Open Modal"), false, () => { CustomModal.Open(); });
menu.ShowAsContext();
}
}
}
public class IssueDemo : MonoBehaviour
{
}
I tried to delay the modal opening and I noticed that the window is still opening white, I also noticed that if I click anywhere after the GenericMenu item’s callback and before the modal opening then it’s opening with no trouble (no white background and with visible content). So maybe it’s a focus issue? I tried to set the focus manually after the GenericMenu item’s callback but that didn’t work…