Unity Cloud Code (Beta)
A modern game requires a lot of components in order to be successful, for example an in-game economy, storage for player data and dynamic settings configuration. Using these components from a player device is not always desirable, because it can lead to security issues and introduce unnecessary complexity. Sometimes, there is a need to isolate your game logic away from the client device, such as:
- You need to instantly update the game logic without requiring the player to update their installed version.
- You want to prevent malicious users from altering the client code, changing their state, and cheating. You might also want to prevent users from reverse-engineering your game logic.
- Using multiple online services can make the game feel sluggish or difficult to write on the game client as you integrate with more server-side components.
Typically, you create and maintain a game server that can handle these use cases. However, effectively managing, scaling, and upgrading backend infrastructure can require a lot of effort. You also need to manage the compatibility between hardware, the security of the servers, and writing the API that the game interacts with.
By using Unity's Cloud Code to write stateless server-side code on a fully managed infrastructure, you can primarily focus on developing your game logic. Cloud Code automatically provisions server capacity based on load so you can ensure that your players receive a good experience without any lag or downtime. This also ensures that you only pay for what you use, because there are never any wasted resources when the game is not receiving traffic. In addition, because your code runs in a secure sandbox, you can protect your game logic from reverse engineering. Seamless integration with other Unity services allows you to write code that ties in multiple components without concern for authentication or compatibility. You can instantly deploy code to live games without the need to roll out a client update that would require users to update their installs.
The following process details a typical development cycle:
- Create a script. Select the type (currently only API scripts are supported) and add custom parameters.
- Write the code. Build from the example scripts or start from scratch. Easily integrate with other Unity services by using the Cloud Code API clients.
- 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.
- Publish the script. Select Publish, makes the script available to the game client. This is the main mechanism for doing live updates on scripts, which are immediately displayed in the game.
- Integrate the script with your project. Import the Cloud Code SDK into your game and use one of the provided methods to call your script.
Example use cases
You can write much of your game logic with Cloud Code. However, it might not be obvious how to connect different services together from within scripts or how that would fit in as a game mechanic. Explore the Use cases to get a better understanding of how Cloud Code scripts are written and what problems they can solve. Examples include server time anti-cheat mechanisms, in-game coupons, and daily rewards.
Download the Unity Gaming Services Samples project to see how to implement Cloud Code to solve common game development challenges: