Cloud Code JavaScript scripts

Cloud Code scripts use JavaScript. You can call these scripts from games built with Unity, or from any other client or server.

Authoring methodDescription
Unity Cloud DashboardUse the Unity Cloud Dashboard to create and test scripts. You can access other Unity Gaming Services from the same place, such as Remote Config.
Unity EditorUse the Unity Editor to write, test and bundle scripts. You can integrate with the deployment window, automate your workflow and deploy Cloud Code alongside other Unity services.
Unity Gaming Services CLIUse the CLI to deploy and manage scripts from the command line. Deploy multiple Unity service configurations at once, and integrate with CI/CD.

Typical workflow

The following process details a typical development cycle:

  1. Create a script. Create a Cloud Code script through the Unity Cloud Dashboard and add custom parameters.
  2. Write the code. Build from the example scripts or start from scratch. Easily integrate with other Unity Gaming Services by using the Cloud Code JavaScript SDKs.
  3. Test and debug. Select Run on the dashboard and test the result of your function. Use the provided test players to validate the interaction with other services or add logging statements to debug issues. For more information, refer to the page on how to Test run the script.
  4. Publish the script. Select Publish to make the script available to the game client. This is the main mechanism for adding live updates on scripts, which immediately display in the game.
  5. Integrate the script with your project. Import the Cloud Code SDK into your game and call your script from Unity runtime. You can run the script with the REST API, or from a Multiplay server.

Example use cases

You can write a lot of your game logic with Cloud Code. For example, you can connect to different services from within scripts. To understand how to connect to services and how it works as a game mechanic, you can explore the use cases. The examples include server time anti-cheat mechanisms, in-game coupons, and daily rewards.

For more advanced use, download the Unity Gaming Services Samples project to learn how to solve common game development challenges with Cloud Code, and read the Advanced use cases.

Fundamental concepts

Learn about the fundamental concepts of Cloud Code scripts:

Create a scriptLearn how to create a script.
Script structureUnderstand the structure of a script.
Write scriptsLearn how to write scripts using the Unity Cloud Dashboard, UGS CLI, REST API or the Unity Editor.
Run scriptsLearn how to run scripts from Unity runtime, with REST API or from a Multiplay server.
Test run the scriptLearn how to test your script.
Error handlingLearn how handle errors in your scripts.
LoggingLearn how to use logging to debug your script.

Improve your workflow

To streamline the development and deployment of your scripts, you can automate the process:

Integrate with CI/CDIntegrate the deployment of your script with your CI/CD pipeline.
Integrate with Unity EditorLearn how to write, test and bundle scripts in the Unity Editor.

Integrate further

You can integrate modules with other Unity Gaming Services and any external services, and access cross-player data.

To integrate with other services, you can install the Cloud Code JavaScript libraries or use a HTTP client.

AuthenticationLearn how to authenticate your game client with Cloud Code.
Service and access token supportLearn how to use service and access tokens to authenticate your scripts.
Available librariesFind the available UGS SDKs for with Cloud Code scripts.
Access controlLearn how to control access and prevent unwanted usage.
Integrate with Unity ServicesLearn about how to connect Cloud Code to other Unity services.
Integrate with external servicesLearn how to integrate with external services.
Interact with cross-player dataLearn how to access and update data for other players.
TriggersLearn how to use triggers to automate server side actions.