Unity Cloud Dashboard
The Unity Cloud Dashboard is a simple way to get started as it allows you to take full control of your scripts through a graphical interface. This section covers how you can preview, create, edit, and delete your scripts.
Preview scripts
You can access a list of all Cloud Code scripts for an environment from Unity Cloud Dashboard. To access it:
- In the Unity Cloud Dashboard, within the LiveOps section, select Cloud Code.
- Select Scripts.
- Select an environment from the list of environments.
A list of all Cloud Code scripts in the selected environment for the project appears. The table contains the name, type, last published date, and version. You can sort the table by script name or use the pagination to see the full range of scripts.
Create a script
Create your first script in the Unity Cloud Dashboard to get started with Cloud Code.
Within the LiveOps section, go to Cloud Code, then select Explore.
Select Create a new script.
Each script is linked to a specific environment.
Fill in the following information:
Name: A descriptive name for your script, used to identify and execute the script in the Cloud Code backend. Script names must be unique across the project and environment, only contain letters, numbers, underscores and dashes, and not exceed 50 characters.
Type: The type of the script.
Currently, Cloud Code only supports triggering scripts from a game client through API calls.
Select Next.
In the next window, fill in the information for the type of script you selected.
The next screen is the script editor where you can test and edit the code and its details.
Adding parameters
After adding a script, select + Add parameter. Specify the parameters the script accepts from the game. You can access parameters from the script code as named properties.
Fill in the following information:
Parameter name: The name of a parameter that's available to your script when triggered. The parameter name must be unique for the script, only contain letters, numbers, underscores, and dashes, and fewer than 50 characters.
Type: This field determines the data type validation that Cloud Code performs upon each request.
Select one of:
- String
- Numeric
- Boolean
- JSON
- Any
Required: Enable this field to validate that the parameter was passed in the request. Executing a script through the Cloud Code API without all its required parameters results in an error.
Cloud Code validates these parameters when it executes the script. Invalid input parameters fail the Cloud Code API call.
Repeat these steps to add more parameters, to a maximum of 10.
Select Add.
Script editor
The browser-based script editor shows you errors in your code and provides JavaScript auto-complete functionality.
Within the Run Code tab, you see the following:
- The Script Code section contains your script code.
- The Parameters table lists all the parameters you created and their values, as well as the ability to generate test Player IDs. Parameters marked as required appear before any optional parameters.
- The Response/Logs/Request tabs show information about your script after it runs.
- The Beautify button automatically reformats the code to optimize its legibility.
The editor has the following features:
- Simple code auto-complete for simple JavaScript features.
- Annotations for common issues such as syntax errors, missing semicolons, and unreachable code.
- Annotations for errors that occurred during test execution such as type errors, range errors, and other thrown errors.
Each new script is pre-populated with an example to get you started quickly.
Script details
Select the Details tab to view the following information:
- Script name
- Type
- Last published date
- Last published version
You can also see a table of the script parameters you created earlier. You can edit these parameters or create new ones from this table.
Saving and publishing
In the Run Code tab, when you change the code in the Script Code window, Cloud Code activates the Save script button. Select Save script to save those changes to the working copy. The code is saved but not yet live, so there is no danger of breaking your game.
When there are no pending code changes in the editor, Cloud Code activates the Publish version button. After you select this button and confirm the publication of the script in a dialog, your script becomes live. When a game client calls the Cloud Code API, your script executes in the Cloud Code backend.
A working copy of the script remains editable and has no effect on the player’s game experience. Although published versions of the code are read-only, you can publish them again. This working copy is useful in case something unexpected happens with the published script and you want to roll back to a previous version of the script that worked.
When you publish an older version, you create a duplicate copy as a new version. When you publish the script, you update the live version of your game, so be sure that the script works as intended before publication.
You can't republish the currently active version of a script. This means that if the selected script version (the working copy or a previous version) is identical to the script in the live version of the game, Cloud Code disables the publish functionality until there is a difference between the two.
The version number increments every time you publish a script, but Cloud Code only retains the latest 10 versions.
Delete a script
To delete scripts from the Unity Cloud Dashboard:
Navigate to the Scripts list page.
Select the bin icon. A dialog appears warning you that deleting this script cannot be undone.
Deleting a published script that is in use by a live game causes errors in the game client.
Confirm the deletion by selecting Delete.