Run a local Cloud Code server
Start a Cloud Code server directly on your local machine.
Read time 6 minutesLast updated 2 days ago
A local Cloud Code server lets you run and debug C# modules directly on your machine, so you can iterate on game server logic without pushing every change to a remote environment. You can also attach a debugger to the local process to set breakpoints, step through execution, and inspect memory while in Play mode.
Prerequisites
Before you start, make sure your project meets the following prerequisites:
- Unity 6.7 or later.
- The Unity Editor is set up to use Cloud Code modules.
- An environment is selected in the Deployment window. Refer to Set up the Deployment window.
- If you have existing modules, they reference the following NuGet package versions. Modules you create in the Unity Editor reference these packages automatically.
- v0.0.27 or later
com.unity.services.cloudcode.apis - v0.0.9 or later
com.unity.services.cloudcode.core
- You have the ASP.NET Core Runtime 10.0 (Microsoft) installed on your machine. The .NET Runtime download alone isn't enough to start the local server.
Enable the Cloud Code toolbar button
You can access all local server settings and operations through the Cloud Code toolbar button. This button is disabled by default. To enable the Cloud Code toolbar button:
- Select the More (⋮) menu in the toolbar.
- Select Services > Cloud Code.
The Cloud Code toolbar button now appears in the Editor's toolbar.

Enabling Cloud Code in the Editor from the toolbar
Execute modules on the local server
To execute C# server functions on the local server from your game, select the Cloud Code toolbar button, then Start Local Server.

The Start Local Server button in the toolbar
Starting the local server automatically compiles and deploys all Cloud Code modules in your project onto that server. The Cloud Code toolbar button, and the window that button opens, displays the state of the local server, for example, idle, starting, running, and its process ID (PID).

The Stop Local Server button in the toolbar
Alternatively, you can reload subsequent code changes to your modules onto the started server by restarting the server, or redeploying the desired module through the Deployment window.

Redeploying a module in the Deployment window
With your deployed C# modules on the local server, server calls made from your game in Play mode are now redirected to the local server. Note that the determination of a local versus remote server call is made immediately when you enter Play mode in the Editor. If the local server is running, all server calls are directed locally. Likewise, if the local server isn't running as you enter Play mode, all server calls are directed remotely.
Reset local state
The default behavior of scoped data on a local server is to persist even after you restart the server or redeploy a module. However, in certain situations, your development scenario might require you to reset the data of your or scope.
PlayerMultiplayerSessionTo reset your local scope state:
- Select the Cloud Code toolbar button.
- If your server is currently running, select Stop Local Server.
- For the Local Server State option, select Clear.

The Local Server State Clear button in the toolbar
Clearing the state removes all persisted scope data from the local server.
Find the local server's logs and data
The local server writes its log files, and keeps the modules deployed to it and its scope state, in a folder in your user data folder. The location of that folder depends on your operating system and on the Unity Editor version you use:
UnityCloudCodeOperating system | Editor version |
|
|---|---|---|
| Windows | Any | |
| macOS | Unity 6.7 | |
| macOS | Unity 7 | |
| Linux | Any | |
On Linux, and on macOS with Unity 6.7, the folder moves under the folder that the environment variable points to, if you've set it.
XDG_DATA_HOMEThe folder contains the following subfolders:
UnityCloudCode- : One
Logsfile for each local server start. When the server starts, the Editor deletes the oldest files and keeps only the most recent ones.server-<date>-<time>.log - : The modules deployed to the local server. The
Modulessubfolder contains the scope state.Modules/ScopeState
Configure additional local server settings
To configure additional settings for local Cloud Code servers, follow these steps:
- In the Editor, select Edit > Project Settings > Services > Cloud Code.
- To show the local server's internal system logs in the Console window, in addition to your module's own logs, enable Verbose Logging. This setting applies to the entire Cloud Code package and is disabled by default.
- If the default values don't work for your project, adjust the following settings in the Local Debugging section before you start the server:
- Port: The local port on your machine on which the local server listens for calls. The default port is .
14750 - Secrets File: A JSON asset containing key-value secret pairs to be retrieved in your Cloud Code functions. If no file is assigned, select Create and assign to generate in the project. If you've already assigned a file, select Edit to open it in your external editor. The file must be a flat JSON object whose values are all strings. Nested objects and numbers aren't supported.
Assets/CloudCode/localServerSecret.json
- Port: The local port on your machine on which the local server listens for calls. The default port is
The following example shows the expected format of a secrets file:
{ "SECRET_EXAMPLE": "replace-with-your-secret-value"}
The following code shows how to update to reference the latest APIs for local Cloud Code servers to retrieve secrets in Cloud Code modules.
ModuleConfigusing Unity.Services.CloudCode.Apis.Extensions;using Unity.Services.CloudCode.Core;public class ModuleConfig : ICloudCodeSetup{ public void Setup(ICloudCodeConfig config) { config.AddGameApiClient(); }}