Test run the script

The Unity Cloud Dashboard allows for test-running scripts in the environment in which they are saved. Unity uses the same environment when communicating with other Unity services through Cloud Code scripts. The images in this topic demonstrate a test run of the sample script that simulates rolling a six-sided die.

Refer to Limits for more information on script execution limitations.

Generate a test Player ID

An authenticated game client calls Cloud Code scripts; the implication being that a player took an action that would trigger the game client to execute a specific script. To simulate this, use the Cloud Code editor to generate an anonymous Player ID and access token that is then exposed to the script at runtime. Player IDs are generated for the currently selected environment and do not exist in any of the other environments for the project.

These anonymous player access tokens are valid for one hour before they expire, and you can generate a new token by selecting Generate in the Run Code tab’s Player ID section.

These anonymous Player IDs are useful because you can trace the changes made in other services during a test run, for example, when using the Cloud Save or Economy SDKs in a Cloud Code script.

Anonymous Player IDs persist throughout browser sessions and are prepopulated for each project. This allows for a single Player ID to be used between multiple scripts, which can simulate the usage from a game client.

Test runs are not possible without a valid Player ID. If the Player ID has expired, select Run to view a dialog that describes the error.

Input parameters

The input fields of the parameters match the types of the input parameters specified in the Details tab. This means, for instance, that a Boolean parameter can only be true or false, and a numeric parameter can only be a number.

You must always supply the required input parameters for a test run. If you don’t, the dashboard indicates the missing field with an asterisk next to the parameter name, and a red error label if you interacted with the parameter input but didn’t complete it.

Testing previous versions

Selecting a version from the list of versions updates the code and the parameters in the Run Code tab. This makes it possible to run previously published versions of a script, which you can use for debugging, for example, if a newer version has introduced a bug that did not exist in older versions.

Test run response

Cloud Code populates the Run Code tab’s Response/Logs/Request section when you execute a test run. Execute a test run by selecting Run at the top of the Parameters section.

  • The Response tab shows the amount of time it took to execute the script, including network latency between the browser and the Cloud Code service. It also shows what the script returned during its execution.
  • The Logs tab shows any logged information captured during the execution of the function.
  • The Request tab shows the input parameters the script was called with.