Cloud Code

Cloud Code is a serverless compute service that allows you to write and run code in the cloud. You can use Unity's Cloud Code to write stateless server-side code on a fully managed infrastructure. Cloud Code is a fully managed service that automatically scales to meet your traffic demands. You can focus on the development of your game logic and isolate it from the client to prevent cheating.

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 backend, and to deploy solutions such as in-game economy, storage for player data, and dynamic settings configuration, while you keep your game logic secure.

Cloud Code C# modules cannot use classes from the UnityEngine namespace or anything else in the Unity's scripting API. This is because Cloud Code uses the open-source .NET runtime. This is separate from the Unity runtime and does not rely on any of its scripting backends.

Solutions with Cloud Code

ProblemSolution
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.

Cloud Code samples

The following tutorials show how you can use Cloud Code triggers in combination with other UGS products for specific outcomes.

Note: For more advanced sample projects, you can refer to the UGS use cases sample project.

TutorialServices
Reward top players with in-game currency at the end of seasonLeaderboards
Economy
Initialize newly signed-up players with default configuration valuesAuthentication
Cloud Save
Send a push message to the player whose score was beatenLeaderboards
Announce a level up to all players in joined lobbiesCloud Save
Lobby
Tune game difficulty level for individual playerCloud Save
Leaderboards
Authentication

Use Cloud Code with modules and scripts

To call Cloud Code from games, you can 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 code: Cloud Code C# modules and Cloud Code JavaScript scripts.

To choose which method fits your needs, review the following outline .

Cloud Code C# modulesCloud Code JavaScript scripts
Runtime.NET 7Node.js 14
LanguageC#JavaScript
DeployingEditor, Command line or admin API.Editor, dashboard, command line, or admin API.
RunningSDK or runtime API.SDK or runtime API.
External library supportNuGet package manager and public internet endpointsPublic internet endpoints.

Cloud Code C# modules cannot use classes from the UnityEngine namespace or anything else in the Unity's scripting API. This is because Cloud Code uses the open-source .NET runtime. This is separate from the Unity runtime and does not rely on any of its scripting backends.

Cloud Code interfaces

There are multiple ways to integrate and manage your application with Cloud Code:

InterfaceSupportDescriptionUsage
Cloud Code SDKScripts 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 Cloud DashboardScripts 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 interfaceScripts 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 APIScripts 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 APIScripts 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.
DeploymentsScripts and modules.An extension of Unity Editor and UGS CLI.Use deployments to configure Cloud Code with files instead of the Unity Cloud Dashboard. Include these files as part of version control, and minimize context switching with the Unity Cloud Dashboard.

To understand how to deploy and run your code, follow one of the options in the Take the next step section.

Take the next step

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 C# modules.

Cloud Code JavaScript scripts

Write server-side code with a easy to iterate language. Take the advantage of using the same ecosystem if you come from a JavaScript frontend background. Bundle your code with reusable pieces through CommonJS and ECMAScript module systems supported out-of-the-box with the Cloud Code command line.

Get started with Cloud Code JavaScript scripts.