@uMathieu I submitted report (Case 1333331) with minimal example. In fact, it consist of two scripts for two windows - main and modal (code is below). Open Main Window with menu Test → Main Window. Opening modal window starts in background:
- UI Toolkit scheduler,
- loop of 5 async tasks,
- implements Update() method
None of above is called if modal window was started with EditorWindow.ShowModalUtility()
If you comment line with EditorWindow.ShowModalUtility(). Then all above runs well, but window is not modal.
Regarding repaints: changes into UI tree are displayed immediately. But if change is made from modal window into parent, then parent is not changed until modal is closed (then all changes appear). I found, that I can force parent window to repait by calling Repaint() explicitlly. This is not needed if child window is not displayed as modal.
MainWindow.cs
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class MainWindow : EditorWindow {
[MenuItem("Test/Main Window")]
public static void CreateMainWindow() {
MainWindow window = GetWindow<MainWindow>("Main Window");
window.minSize = new Vector2(200, 200);
}
public void CreateGUI() {
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/MainWindowTemplate.uxml");
rootVisualElement.Clear();
visualTree.CloneTree(rootVisualElement);
Button button = rootVisualElement.Q<Button>("button");
button.clicked += HandleShowModal;
}
private void HandleShowModal() {
ModalWindow.CreateModalWindow();
}
}
MainWindowTemplate.uxml
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<ui:VisualElement style="align-items: center;">
<ui:Button text="Show Modal" display-tooltip-when-elided="true" name="button" style="width: 200px; align-items: auto; margin-top: 20px; margin-bottom: 20px;" />
</ui:VisualElement>
</ui:UXML>
ModalWindow.cs
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class ModalWindow : EditorWindow {
private double _time = 0;
public static void CreateModalWindow() {
ModalWindow window = GetWindow<ModalWindow>("Modal Window");
window.minSize = new Vector2(200, 200);
window.ShowModalUtility();
}
public void CreateGUI() {
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/ModalWindowTemplate.uxml");
rootVisualElement.Clear();
visualTree.CloneTree(rootVisualElement);
Button closeButton = rootVisualElement.Q<Button>("closeButton");
closeButton.clicked += () => {
Close();
};
SetPeriodicEvent(); // UI Toolkit scheduled item
AsyncTask(); // C# async task
}
private void SetPeriodicEvent() {
int count = 0;
var scheduledItem = rootVisualElement.schedule.Execute(() => {
Debug.Log($"Modal Window scheduled task - count = {count++}");
});
scheduledItem.Every(1000);
}
private async void AsyncTask() {
int count = 0;
for (int i = 0; i < 5; i++) {
await Task.Delay(1000);
Debug.Log($"AsyncTask - (count = {count})");
++count;
}
}
private void Update() {
if (EditorApplication.timeSinceStartup - _time > 1) {
_time = EditorApplication.timeSinceStartup;
Debug.Log($"Unity Update() tick.");
}
}
}
ModalWindowTemplate.uxml```<ui:UXML xmlns:ui=“UnityEngine.UIElements” xmlns:uie=“UnityEditor.UIElements” xsi=“http://www.w3.org/2001/XMLSchema-instance” engine=“UnityEngine.UIElements” editor=“UnityEditor.UIElements” noNamespaceSchemaLocation=“…/…/UIElementsSchema/UIElements.xsd” editor-extension-mode=“True”>
<ui:VisualElement style=“align-items: stretch; flex-grow: 0;”>
<ui:Label text="When modal window opens it starts three types of periodic tasks:
- UI Toolkit scheduled item
- C# async task (5 times)
- EditorWindow.Update()
None of these tasks is executed if modal window was open with EditorWindow.ShowModalUtility(). C# tasks start to execute after modal is closed." display-tooltip-when-elided=“true” style=“margin-left: 10px; margin-right: 10px; margin-top: 20px; margin-bottom: 0; align-items: auto; flex-grow: 1; border-left-color: rgb(128, 128, 128); border-right-color: rgb(128, 128, 128); border-top-color: rgb(128, 128, 128); border-bottom-color: rgb(128, 128, 128); border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; white-space: normal;” />
<ui:VisualElement style=“width: auto; flex-grow: 1; flex-shrink: 0; align-items: center;”>
<ui:Button text=“Close” display-tooltip-when-elided=“true” name=“closeButton” style=“width: 200px; margin-top: 20px;” />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>