Hello Everyone.
For an editor tool I am working on I need to create a modal window that let the user pick an asset and in order to find the available assets I need to use SearchService.Request().
The problem is, when a modal window is opened, some of the editor internal updates are blocked and, as a result, the search request doesn’t complete.
To be more accurate, while a modal editor window is opened EditorApplication.update and EditorWindow.Update() are no longer called but async functions and VisualElement schedulers still are. This behavior is incoherent between platforms, it happen on Windows but not on Linux (I didn’t test on Mac).
Before you ask, yes, I NEED a modal window for this. There are just too many things that could break if the user could tamper with other parts of the editor while the window is opened. And yes I have to perform the search request while the window is opened, I can’t do it before. So this is a major problem for me. Modal windows are a very common UX paradigm and there is no reason we shouldn’t use them within the Unity editor.
I opened a bug report about the modal window blocking the editor (IN-42896) and it was closed as a won’t fix.
So the unholy solution I came up with is to call Internal_InvokeTickEvents myself while the window is open.
internalTick = ReflectionUtils.GetStaticMethod(typeof(EditorApplication), "Internal_InvokeTickEvents", new Type[] {});
var searchList = SearchService.Request(searchContext, SearchFlags.WantsMore);
using (var it = searchList.GetEnumerator())
{
internalTick?.Invoke(null, new object[] {});
while (it.MoveNext())
{
internalTick?.Invoke(null, new object[] {});
var item = it.Current;
// do something with item
await Task.Yield();
}
}
You don’t like it? Me neither!
I really need a better solution for that. There is no reason a modal window should block the search function. So here are some propositions that could sole this issue:
- Don’t block editor updates while a modal window is opened. I understand that modifying this behavior could cause regressions but the current behavior is not good and incoherent between platforms. Maybe this could be configurable by the script. Maybe when opening a modal window the user could pass an optional parameter telling Unity if the updates should be blocked or not.
- Make SearchService not rely on editor updates. Looking at the code I don’t even understand why it needs it. Calling MoveNext() should be enough for the request to update.
Please Unity devs, I need a solution for this.
Thank you very much.
