Start a new topic

Trigger to record gameEnded event, unity sdk.


I am using deltaDNA unity sdk in the game that I am creating.

I cant figure out how/when to record the "gameEnded" event successfully.

All the triggers I have tried so far, didnt worked in the devices.

Unity has a callback called "OnApplicationQuit", but when I try to record the event in this method, the event doesn't get sent to deltaDNA. I believe that at the context of this "OnApplicationQuit" callback, deltaDNA sdk is not working anymore.

I tried also in the "OnDestroy" and "OnDisable" of DDNA object, but unsuccessfully as well.

I saw that DDNA.cs records the "gameEnded" event in the function StopSDK, but this is not automatic, so I still need to call it at the right moment/trigger.

Turns that the player can close my game in multiple ways: by back/home, by task manager, or the device can kill the application by itself.

So I need something like "OnApplicationQuit" to trigger the event, but a little bit earlier, when deltaDNA is working.

Maybe a callback on DDNA called right before the sdk stop working, like "this is your last chance to record an event".

Do you know how I can achieve that? I want to avoid changing your code at all.



The gameEnded event is a difficult event to use for exactly the reason you're mentioning here.

Typically the gameEnded is only implemented when there is a definite way to tell the game is ending, for example when the game is part of a bigger set of games within one application. Otherwise it is too unreliable to actually provide any useful information. Games on mobile are often put in the background and will be destroyed by the os on power down or not at all.

However, It is possible to use the gameEnded event by recording it and initialising an upload straight away in the OnApplicationQuit.

I hope this is of any help.

Thanks Steven, I will try forcing an Upload, then I tell you if worked.

Hi Steven. Its no working yet, I dont see the gameEnded in the board or in the event browser.

Look what I have done:


private void OnApplicationQuit()
    if (DDNA.Instance != null)
        Dictionary<string, object> eventParams = new Dictionary<string, object> ();
    // Using timeSinceApplicationStart, because Time.time in this moment is    always 0
         int sessionElapsedPlaytime  = Mathf.RoundToInt(timeSinceApplicationStart);
         eventParams.Add("sessionElapsedPlaytime", sessionElapsedPlaytime);
         DDNA.Instance.RecordEvent("gameEnded", eventParams);
         // Force upload
         Debug.Log("Sent gameEnded event, sessionElapsedPlaytime: " + sessionElapsedPlaytime);
 } }
Login or Signup to post a comment