I'm finding out that unity does not fully destroy all game objects on application quit. The result is that I have a number of async/await functionality that eventually runs and I can see output stream into the console long after the editor has been stopped.
Currently I'm manually disposing / destroying objects in OnApplicationQuit
but this seems a bit silly.
Is there a more proper way to make sure all objects in the editor are fully destroyed on application quit ?
** EDIT **
How I'm using async code
public static async Task<Texture2D> DownloadTexture(string uri)
{
using (
UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(uri, true)
)
{
var asyncOp = uwr.SendWebRequest();
if (WeatherTracker.instance == null)
{
uwr.Abort(); // todo: something related to this is crashing the editor while textures are still being download @jkr
return null;
}
while (asyncOp.isDone == false)
await Task.Delay(1000 / MainCamera.instance.MaxFrameRate);
// return this.uwr.SendWebRequest();
// Debug.Log($"download tex {z}/{x}/{y}");
if (uwr.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"{uwr.error}: {uri}");
return null;
}
else
{
return DownloadHandlerTexture.GetContent(uwr);
}
}
}
Destroy
but Destroy is never called when you stop running your application via the editor (2021.2.3f1). My workaround for now is to triggerDestroy
inside ofOnApplicationQuit
and even then SOME parts of my script continue to run. It's overkill but I've gone as far as telling coroutines and awaits to check for a running instance of the application before continuing. \$\endgroup\$OnDestroy()
? I've just tested in Unity 2020.3.18f and verified thatOnDestroy()
is called as expected when exiting play mode in the editor. If you're not observing that in your version, that sounds like a bug to report to Unity. Can you edit your question to show a Minimal Complete Verifiable Example so we can use it to reproduce the problem and test potential fixes? \$\endgroup\$UnityEngine.Object.Destroy
and after a while failed to differentiate that fromMonoBehavior.OnDestroy
. They are obviously different but my brain stopped working correctly. Thanks for being patient with me. \$\endgroup\$