Cloud Code

A modern game requires a lot of components in order to be successful, such as an in-game economy, storage for player data, and dynamic settings configuration. Using these components from a player device is not always preferable because it can lead to security issues and introduce unnecessary complexity. Sometimes, you need to isolate your game logic away from the client device, such as when:

  • 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.
  • You want to use multiple online services without making 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 of many components, including:

  • Hardware
  • Server security
  • The game application programming interface (API)

By using Unity's Cloud Code to write stateless server-side code on a fully managed infrastructure, you can focus more 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. Cloud Code 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 rolling out a client update that would require users to update their installs.

Cloud Code functions are written in JavaScript. You can call these functions from games by using an HTTP request. Write, test, and debug functions from the Unity Dashboard in the same place you define the configuration for other services, such as Remote Config.

Cloud Code interfaces

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

  • The Cloud Code software development kit (SDK) allows you to integrate your Unity project with Cloud Code. Use the SDK to call module endpoints or to call scripts.
  • The Unity Dashboard provides a web-based interface to manage Cloud Code configuration and settings.
  • The Runtime API allows you to integrate Cloud Code with any application and game engine.
  • The Admin API allows you to manage Cloud Code configuration through programming.
  • Deployments are supported for the Unity Editor and the Unity Gaming Services command-line interface (UGS CLI). Deployments allow you to configure Cloud Code using files instead of the Unity Dashboard. Include these files as part of version control, and minimize context switching with the Unity Dashboard.
  • The Unity Gaming Services command-line interface allows you to interact with Cloud Code programmatically. Use command-line tools to automate repetitive tasks and workflow.

Modules and scripts

Cloud Code supports two types of code: Cloud Code C# modules and Cloud Code JavaScript scripts. Review the following outline to pick what fits your needs.

Cloud Code C# modulesCloud Code JavaScript scripts
Runtime.NET 7Node.js 14
LanguageC#JavaScript
DeployingVia command line or admin API.Via editor, dashboard, command line, or admin API.
RunningVia SDK or runtime API.Via SDK or runtime API.
External library supportVia NuGet package manager.Via public internet endpoints.

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

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.

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