No Events are send OnApplicationQuit on Windows Build

I have a couple of custom events that are fired OnApplicationQuit.
It works fine in the Editor, my custom events and “gameEnded” are fired when I end playmode.
In Windows Builds I get the Analytics debugs for my custom evetns and “gameEnded”:
Recorded event gameEnded at 2022-12-14 10:50:28.188 +01:00 (UTC)
Serializing event gameEnded for dispatch…

But the debug
Uploading events…
Events uploaded successfully!
is missing.

In WebGL I managed to get my custom events fired, when the browser tab is closed, but the “gameEnded” event is also never fired.

Is there a special trick to get those events? Or is is just a bug?

Hi @manuelgoellnitz ,

Thanks for reaching out! We attempt to send the gameEnded event if the game is shut down, whether it’s closed by Alt+F4, swiped off, or closed with a properly-implemented Quit button. However, this is contingent on the OS letting it shut down gracefully rather than just killing it, as sending events does take some amount of time. If they don’t make it out, the gameEnded event may be cached on disk, so it should then get uploaded the next time the player starts the app… Though, yes, it is quite unreliable because of the nature of trying to do work while being closed down.

I see in the logs you’ve shared that the gameEnded event is recorded. Is it sent in the 1st upload on the subsequent session? It should be cached, held, and uploaded on the next session.

Best,
Randy

As I saw it, The events are send out via a webrequest, which is never callled, when the application quits.

So I made a workaround like this:

void Start()
{        
     Application.wantsToQuit += WantsToQuit;
    
}

private bool WantsToQuit()
{
    if (sendingQuitAppsComplete)
        return true;

   StartCoroutine(DelayQuitCoroutine());
   return false;
}

private IEnumerator DelayQuitCoroutine()
{
   //send out custom events here
   //show some kind of "application is quitting"
   yield return new WaitForSeconds(1f);
   sendingQuitAppsComplete = true;   
   Application.Quit();
}

I basically delay the quitting of the application by one second.
This gives the analytics system enough time to send the gameEnded. Or at least my custom events are send then.

2 Likes

Hi @manuelgoellnitz ,

That’s a really awesome workaround. I’m going to hold on to that for future reference. I see you’re getting your custom events, but are you also getting your gameEnded events consistently?

Best,
Randy

I looked into it again.
The Unity event “gameEnded” is still not send (not even after restarting the app). But my custom events are, which was good enough for my purpose.

1 Like

I have the same issue, and after updating tot 2023.2 it got worse: the application crashes during the attempt. See the log in attachment.

9480196–1333099–Player.log.txt (38.4 KB)

I can confirm this!

On Unity 2023.2.0.b14 the crash does not happen

1 Like