# Local Cloud Code server

> Start a Cloud Code server directly on your local machine.

> **Important:**
>
> This page describes an experimental feature that might change significantly before release. It's not recommended to use or rely on experimental features in production environments due to potential instability.

You can accelerate back-end development by instantiating a Cloud Code server with [C# modules](/cloud-code/modules/overview.md) deployed directly on your local machine. With this local Cloud Code server, you can iterate rapidly on game server logic in isolation, bypassing the need to push to a remote environment for every change.

More importantly, a local Cloud Code server unlocks diagnostic capabilities by allowing you to attach a debugger to the local process, granting the ability to set breakpoints, step through execution, and inspect memory to resolve complex server issues at runtime in Play mode.

## Prerequisites

Before you start, make sure your project meets the following prerequisites:

1. Unity 6.3 or later.
2. Follow the [Cloud Code modules](/cloud-code/modules/overview.md) steps to [set up the Unity Editor](/cloud-code/modules/getting-started.md#set-up-the-unity-editor).
3. If you have existing modules, ensure you reference the following NuGet packages:
   * `com.unity.services.cloudcode.apis` v0.0.26 or later
   * `com.unity.services.cloudcode.core` v0.0.4 or later
4. You have [.Net 9.0](https://dotnet.microsoft.com/en-us/download/dotnet/9.0) (Microsoft) installed on your machine.

> **Note:**
>
> Local Cloud Code servers are only supported for [Cloud Code modules](/cloud-code/modules/overview.md). [Cloud Code scripts](/cloud-code/scripts/overview.md) aren't supported.

## Local 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:

1. If not already done, update your scripting define symbols.
   1. In the Editor, go to **Edit** > **Project Settings** > **Player**.
   2. Under **Script Compilation** > **Scripting Define Symbols**, select **+**.
   3. Enter `UNITY_SERVICES_CLOUDCODE_EXPERIMENTAL`.
   4. Select **Apply**, then save your project.
2. Select the **More** (⋮) menu in the [Toolbar](https://docs.unity3d.com/Manual/Toolbar.html).
3. 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:**
![Screenshot showing how to enable Cloud Code in the Editor from the Toolbar.](/api/media?file=/cloud-code/media/images/cloud-code-toolbar-enabling.png)

## Executing 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:**
![Screenshot showing the placement of the Start Local Server button in the Toolbar.](/api/media?file=/cloud-code/media/images/cloud-code-toolbar-idle.png)

Starting the local server automatically compiles and deploys all Cloud Code module references in your project onto that server. The **Cloud Code** Toolbar button, and the window it opens, displays the state of the local server, for example, idle, starting, running, and its PID.


**The Stop Local Server button in the Toolbar:**
![Screenshot showing that the Start Local Server button changes to the Stop Local Server button when the server is running.](/api/media?file=/cloud-code/media/images/cloud-code-toolbar-active.png)

Alternatively, you can reload subsequent code changes to your modules onto the started server by restarting the server, or [redeploying the desired module](/cloud-code/modules/getting-started.md#deploy-the-module) through the [**Deployment** window](https://docs.unity3d.com/Packages/com.unity.services.deployment@latest/index.html?subfolder=/manual/deployment_window.html).


**Redeploying a module in the Deployment window:**
![Screenshot showing the options menu to redeploy a module in the Deployment window.](/api/media?file=/cloud-code/media/images/cloud-code-deployment-window.png)

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.

> **Note:**
>
> [Multiplayer Play mode](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest) isn't fully supported with local Cloud Code servers. You can only perform local server calls from [additional Editor instances](https://docs.unity3d.com/Packages/com.unity.multiplayer.playmode@latest/index.html?subfolder=/manual/instance-types/main-and-additional-editor-instances.html) activated after the local server has started. Calls from any other instance types are always directed remotely.

## Local state persistence

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 `Player` or `MultiplayerSession` [scope](/cloud-code/stateful-cloud-code/stateful-cloud-code.md).

To reset your local scope state:

1. Select the **Cloud Code** Toolbar button.
2. If your server is currently running, select **Stop Local Server**.
3. For the **Local Server State** option, select **Clear**.


**The Local Server State Clear button in the Toolbar:**
![Screenshot showing the Clear button used to reset local state from all scopes.](/api/media?file=/cloud-code/media/images/cloud-code-toolbar-idle.png)

> **Warning:**
>
> The **Clear** button isn't targeted to a specific state you want to clear. Selecting **Clear** deletes the state for all scopes.

## Additional local server settings

You can configure the local server with the following additional settings before starting it:

* Port: The local port on your machine on which your local server will listen for calls.
* Secrets file: A JSON asset containing key-value secret pairs to be [retrieved](/services/secret-manager/tutorials/integrations/cloud-code/modules.md) in your Cloud Code functions.

To access these settings, select **Edit** > **Project Settings** > **Services** > **Cloud Code**.


**The Cloud Code Project Settings window:**
![Screenshot showing the Cloud Code Project Settings window.](/api/media?file=/cloud-code/media/images/cloud-code-settings.png)

The following code shows how to update `ModuleConfig` to reference the latest APIs for local Cloud Code servers to [retrieve secrets in Cloud Code modules](/services/secret-manager/tutorials/integrations/cloud-code/modules.md).

```csharp title="Update ModuleConfig to retrieve secrets"
public class ModuleConfig : ICloudCodeSetup
{
    public void Setup(ICloudCodeConfig config)
    {
        // Old approach - will be deprecated, please remove.
        // config.Dependencies.AddSingleton<IGameApiClient>(GameApiClient.Create());

        // Replace with this for version v0.0.26+
        config.AddGameApiClient();
    }
}
```
