Skip to main content
Version: 28.0.5

Unity Script Execution and Game State

The Skillz SDK will pause Unity when launching and un-pause Unity when launching your game. You can implement OnApplicationPause() to help manage game state. Please note that when OnApplicationPause(false) is called, un-pausing Unity the Start method will not be called for your script.

This section assumes you are familiar with the Unity Script Execution Order. Please refer to the Unity documentation

Unity Script Lifecycle​

A Unity MonoBehaviour when first instantiated will call Start, but Start will not be called again after Unity is un-paused. If you enter into the same script, which referenced ReportFinalScore, the script will go straight into the Update loop. Please read the Unity Execution for Event Functions for specifics. This shows that when Unity is un-paused the implementation of OnApplicationPause is called first and then the script execution resumes the Update loop. This will happen even if you call LoadScene from OnMatchWillBegin.

You can handle game state and data in several ways. First would be to create variables that track game state and set the correct state within your script. You can implement the OnApplicationPause method to ensure you handle things correctly. Second you can create multiple scenes and transition to other scripts to manage state and present players with the appropriate experience.

TL;DR​

The Skillz SDK will pause Unity when launching and un-pause Unity when launching your game. You can implement OnApplicationPause to help manage game state. Please note that when OnApplicationPause(false) is called, un-pausing Unity the Start method will not be called for your script.

  public void OnApplicationPause(bool pause)
{
// handle state here
}

Game State​

It is a safe assumption that you should always program defensively and not assume that your variables and game state are valid when moving between your game and the Skillz Interface. When entering and exiting the Skillz interface the Skillz SDK will pause and un-pause Unity accordingly. The following provides details on how you can set up your scripts to manage state correctly.