I’ve discovered an issue in the macOS builds of my game. I’m using editor version 2023.2.15f1 URP, and am running an M2 Apple Silicon device on OS X Sonoma 14.4. If I unfocus the game (tile to a different desktop screen or away from the fullscreen game window), while any async function is running, the game freezes upon returning to the game window. This occurs when the player is set to run in the background, as well as when it is set to not run in the background. I’m using the new built-in Awaitable class to handle async methods. This issue does not occur in the editor at all, even when unfocusing and refocusing the editor window, only in builds, and only when I unfocus the window while the operation is occurring. The async methods run as intended without issue if I do not unfocus the game window. The issue has seemingly popped up with any async method, but I’ve most often seen it with my scene-loading method detailed below as an example:
static bool sceneLoading;
static async void HandleSceneTransition(string sceneString)
{
if (sceneLoading) return;
sceneLoading = true;
SceneManager.LoadScene(LOADING);
await Awaitable.WaitForSecondsAsync(0.01f);
var scene = SceneManager.LoadSceneAsync(sceneString);
while (!scene.isDone)
{
await Awaitable.NextFrameAsync();
}
sceneLoading = false;
}
Update: I’ve further tested the issues on an Intel-based Mac running Ventura 13.6 and such issues do not occur. I have also updated the Unity editor to 2023.2.16f1, and my OS to Sonoma 14.4.1, and the issues persist.
I’ve also played around with a testing project that compares using coroutines and async methods to see if both cause issues, and I’ve observed the freezing issue while focusing the game, even when no method/operation is running at all.
I’m glad I’m not crazy! I submitted a detailed bug report on this issue to Unity and now am just waiting to hear back. I’ll post again here as soon as I get some info from them.
I have a similar issue where if I quickly change tabs in our UI which will start/stop async functions on Apple Silicon the game will freeze until I focus another window and then when I focus the game again it un-freezes. I hope this is related to this bug as the fix would be nice.
For reference, once the game freezes almost all activity on the game process stops. CPU and GPU utilization almost drops to zero.
The issue tracker says it’s fixed for 2022 lts but doesn’t mention 2023. I’m hoping it will be fixed with Unity 6 but unfortunately, there’s no specific mention of it on the issue tracker.