Get started
Follow this workflow to create a Unity Cloud Code module in the Unity Editor and deploy it to the Cloud Code service.
Read time 6 minutesLast updated 2 days ago
This page describes the steps to create a Unity Cloud Code module (UCCM) in the Unity Editor and deploy it to the Cloud Code service.
The examples in the workflow create a simple Hello World module. To get started with Cloud Code modules, follow these steps:
- Set up the Unity Editor: Link your Unity Gaming Services project with the Unity Editor, and install the required packages.
- Create a Unity Cloud Code module: Create and compile a module directly in the Editor.
- Deploy the module: Deploy the module to the Cloud Code service, or run it on a local Cloud Code server for testing.
- Call the module function from your game: Call the module endpoint from your game client.
Video walkthrough
Watch the following video for a walkthrough of creating and deploying a C# module in the Unity Editor.
Set up the Unity Editor
To create Cloud Code modules within the Editor, you need to install the required packages and link your Unity Gaming Services project with the Unity Editor.
Access Cloud Code in the Unity Dashboard
To access Cloud Code in the Unity Dashboard, do the following:
- In the Unity Dashboard, go to Development > Products.
- Select Cloud Code.
Link project
Link your Unity Gaming Services project with the Unity Editor. You can find your UGS project ID in the Unity Dashboard.
If you create a new Unity project, you can link your Unity Gaming Services project with the Unity Editor during the project creation process.
If you're working with an existing Unity project, you can link your Unity Gaming Services project with the Unity Editor from the Services window.
-
In Unity Editor, select Edit > Project Settings > Services.
-
Link your project.
If your project doesn't have a Unity project ID:- Select Create a Unity Project ID > Organizations, then select an organization from the dropdown.
- Select Create project ID.
If you have an existing Unity project ID:- Select Use an existing Unity project ID.
- Select an organization and a project from the dropdowns.
- Select Link project ID.
Your Unity Project ID appears, and the project is now linked to Unity services.
Install required packages
To create Cloud Code modules within the Editor, you need to install the following packages:
- Deployment ()
com.unity.services.deployment - Cloud Code (), version 3.0.0 or later
com.unity.services.cloudcode
To install each package, follow the steps in Install a UPM package by name, and enter the package name from the preceding list.
Install and set up .NET
To deploy Cloud Code modules in the editor you need to install .NET.
To set your default .NET path in editor, use the following steps:
- In the Unity Editor, open the Preferences window.
- On Windows, select Edit > Preferences.. > Cloud Code.
- On macOS, select Unity > Settings.. > Cloud Code.
- In the .NET development environment section, modify your .NET path to the one you have installed.
- Select Apply.
Set up the Deployment window
The Deployment window allows you to deploy Cloud Code modules to your remote environment.
If you installed the Deployment package, you can access it from the Unity Editor.
- In Unity Editor versions 2021.3+, select Window > Deployment.
- In Unity Editor versions 2022+, select Services > Deployment.
Before you can use the Deployment window, you need to select the environment you want to deploy to:
- In the Unity Editor, open the Deployment window.
- In the Deployment window, select Deployment Settings.
- In the new Environments window, select an environment from the Editor Environment dropdown.
Create a Unity Cloud Code module
Create a Unity Cloud Code module (UCCM) directly in the Editor. For the full procedure and details about the generated files, refer to Develop Cloud Code modules in the Unity Editor. To learn how a module is structured, refer to module structure.
Deploy the module
To make your module endpoints accessible to the game client, deploy the module to the Cloud Code service. For the deployment steps, refer to Deploy the module.
To test module changes on your machine without deploying them, run a local Cloud Code server instead. For more information, refer to Run a local Cloud Code server.
Call a module function from your game
To verify that your module works, call a module endpoint from your game client. The call goes to the Cloud Code service, or to your local Cloud Code server if it's running when you enter Play mode. The following example calls a function.
SayHelloSDK setup
To call a module function from your game, you first need to set up the Cloud Code SDK in your game client.
- Ensure the service is enabled via the Cloud Code page in the Unity Dashboard.
- Ensure that you have installed both the Cloud Code and the Authentication SDKs from the Unity Package Manager.
- Create a new C# Monobehaviour script in Unity Editor. For more information, refer to Creating and using scripts in the Unity Manual.
Call the module function
The following example shows how to call the module function from the module within your game client.
SayHelloHelloWorldC#
using Unity.Services.Authentication;using Unity.Services.CloudCode;using Unity.Services.CloudCode.GeneratedBindings;using Unity.Services.Core;using UnityEngine;public class TestModule : MonoBehaviour{ private async void Start() { // Initialize the Unity Services Core SDK await UnityServices.InitializeAsync(); // Authenticate by logging into an anonymous account await AuthenticationService.Instance.SignInAnonymouslyAsync(); try { // Call the function within the module and provide the parameters we defined in there var module = new HelloWorldBindings(CloudCodeService.Instance); var result = await module.SayHello("World"); Debug.Log(result); } catch (CloudCodeException exception) { Debug.LogException(exception); } }}
To run the example:
- Attach the script to a GameObject in your scene.
TestModule - If you use a local Cloud Code server, make sure that it's running. Refer to Execute modules on the local server.
- In the toolbar, select Play to enter Play mode.
The Console window displays the result of the call.
SayHelloNext steps
Learn about the next steps after deploying your first module.
Topic | Description |
|---|---|
| Module structure | Familiarize yourself with module structure. |
| Run a local Cloud Code server | Test module changes without deploying them. |
| Stateful Cloud Code | Persist game state across module function calls. |
| Integrate with other Unity services | Integrate modules with other Unity Gaming Services. |
| Integrate with external services | Integrate modules with external services. |
| Write unit tests | Write unit tests for your modules. |
| In-memory cache | Cache slow-changing data between module endpoints. |