Get started with Cloud Code
Explore Cloud Code's main capabilities, fundamental concepts, available interfaces, and main workflow to start running server-side game logic.
Read time 5 minutesLast updated 4 hours ago
Cloud Code is a serverless compute service that lets you write and run game logic in the cloud. Cloud Code scales automatically, and keeps your code secure and separate from the client to prevent cheating so you can focus on game logic instead of managing infrastructure. Cloud Code is fully compatible to integrate with other Unity services, such as Remote Config, Cloud Save, Economy, and Leaderboards. Use Cloud Code with other Unity services to create a complete game back end and deploy solutions such as in-game economy, storage for player data, and dynamic settings configuration, while you keep your game logic secure.
Solutions with Cloud Code
The following table describes common game development problems that Cloud Code can help you solve:Problem | Solution |
|---|---|
| You need to deploy code to live games without rolling out a client update that would require players to update their installs. | Use Cloud Code to update your game logic without the need for players to update. |
| You want to ensure that malicious players can't alter the client code, change their state, or cheat. You might also want to prevent players from reverse-engineering your game logic. | Use Cloud Code to ensure that your game logic runs in a secure sandbox and is separate from the client. |
| You want to use multiple online services but don't want the game to feel sluggish and want it to be easy to write on the game client as you integrate with more server-side components. | Leverage Cloud Code to integrate with other Unity services and write code that ties in multiple components. |
| You need to manage infrastructure to run your game logic and scale it to meet your traffic demands. | Use Cloud Code to write stateless server-side code on a fully managed infrastructure. |
| You don't want to pay for unused resources when the game isn't receiving traffic. | Use Cloud Code to ensure that you only pay for what you use. |
| You need a solution for writing code that ties in multiple components without concern for authentication or compatibility. | Use Cloud Code to write code that integrates with other Unity services with built-in compatibility. |
Code types
To call Cloud Code from games, use integrated Unity SDKs or use the Cloud Code Client API if you need to work outside of Unity Editor. Cloud Code supports two types of server-side code: Cloud Code C# modules and Cloud Code JavaScript scripts.
To choose which type fits your needs, review the following comparison:
Cloud Code C# modules | Cloud Code JavaScript scripts | |
|---|---|---|
| Runtime | .NET 9 | Node.js 14 |
| Language | C# | JavaScript |
| Deploying | Editor, Command line or admin API. | Editor, dashboard, command line, or admin API. |
| Running | SDK or runtime API. | SDK or runtime API. |
| External library support | NuGet package manager and public internet endpoints | Public internet endpoints. |
Cloud Code interfaces
The following table shows several ways to integrate and manage your application with Cloud Code:Interface | Support | Description | Usage |
|---|---|---|---|
| Cloud Code SDK | Scripts and modules. | A software development kit (SDK) to integrate your Unity project with Cloud Code. | Use the SDK to call module endpoints or to call scripts from Unity runtime. |
| Unity Dashboard | Scripts and limited modules support. | A web-based interface to manage Cloud Code configuration and settings. | Create, preview and test-run scripts and preview modules. |
| Unity Gaming Services command-line interface | Scripts and modules. | A command-line interface to manage Cloud Code configuration and settings. | Integrate Cloud Code into CI/CD and iterate with a file-based workflow to deploy Cloud Code alongside other Unity services. |
| Cloud Code Admin API | Scripts and modules. | A REST API to manage Cloud Code scripts and modules. | Create, read, update and delete Cloud Code scripts and modules using the REST API. |
| Cloud Code Client API | Scripts and modules. | A REST API to call Cloud Code scripts and module endpoints. | Call out to Cloud Code scripts and modules through an API call and integrate with products outside of Unity Editor. |
| Deployments | Scripts and modules. | An extension of Unity Editor and UGS CLI. | Use deployments to configure Cloud Code with files instead of the Unity Dashboard. Include these files as part of version control, and minimize context switching with the Unity Dashboard. |
Main Cloud Code workflow
To set up and run Cloud Code, complete the following steps:- Choose your code type, either C# modules or JavaScript scripts. Refer to Code types.
- Review the available Cloud Code interfaces to identify which ones fit your workflow. You'll typically use several across deploying, managing, and calling your code.
- Follow the getting started guide for your chosen code type:
- Get started with Cloud Code C# modules: Write server-side code with a type-safe programming language and powerful .NET components. Consume other content you need in the project bundling dynamic link libraries (DLLs) with tools like NuGet.
- Get started with Cloud Code JavaScript scripts: Write server-side code with a easy to iterate language. Take advantage of the same ecosystem if you come from a JavaScript front-end background. Bundle your code with reusable pieces through CommonJS and ECMAScript module systems supported out-of-the-box with the Cloud Code command line.