Documentation

Multiplayer testing workflow

Follow this workflow to configure Cloud Code and Unity Multiplayer Play Mode to test server calls across multiple instances.
Read time 4 minutesLast updated 2 days ago

You can test Unity Cloud Code modules with multiple instances in Unity Multiplayer Play Mode. A scenario can use a local Cloud Code server or deploy changed modules to a remote environment.
To test Cloud Code with Multiplayer Play Mode, complete the following tasks:
  1. Prepare your project.
  2. Configure a scenario.
  3. Configure Local Instances if you use a local server.
  4. Run the scenario and iterate.

Prerequisites

The Unity Cloud Code and Multiplayer Play Mode integration has the following prerequisite:
  • Use Unity 6.7 or later.

Prepare your project

Set up Cloud Code and the project environment before configuring the scenario. For detailed module setup instructions, refer to Get started with Cloud Code modules.
To prepare your project:
  1. Install the Cloud Code and Multiplayer Play Mode packages.
  2. Link the project to a Unity Cloud project in Edit > Project Settings > Services.
  3. Select an active environment in Project Settings > Services > Environments.
  4. Create the Cloud Code modules (
    .ccmu
    ) that the scenario needs.
  5. If needed, configure a custom port or secrets file in Project Settings > Services > Cloud Code.

Configure a scenario

Use a Multiplayer Play Mode scenario to choose which instances to run and where their Cloud Code requests go. For more information about scenarios and instance types, refer to the Multiplayer Play Mode package documentation.
To configure the scenario:
  1. In the toolbar, select the scenario dropdown, then select Configure Play Mode Scenarios.
  2. In the Play Mode Scenarios window, create or select a scenario.
  3. Add the instances you want to test, such as the main Editor, additional Editor instances, or Local Instances.
  4. In the Additional Configuration section, enable Deploy to Cloud Code.
  5. Set Deploy Target to one of the following:
    • Local to start a local Cloud Code server on your machine.
    • Remote to deploy changed modules to the Cloud Code service in the active environment.
Note
Cloud Code modules have a free tier. If your usage exceeds the free tier, you're billed for the additional usage. For more information about the pricing model, refer to Module cost and Unity Gaming Services pricing.

Configure Local Instances

Local Instances run player builds, so the scenario can't redirect them to a local server. Configure each Local Instance that needs to call the local server. Skip this task if you use a remote target or don't use Local Instances.
To configure a Local Instance for a local server:
  1. In the instance's Advanced Configuration > Arguments, add
    --cloud-code-local-debugger
    . If you use a custom port, add
    --cloud-code-local-debugger=<port>
    with the port value instead. The scenario warning's Copy Argument button copies the argument with your configured port.
  2. Set the instance's build profile to one with Development Build enabled. Release build profiles ignore the local-debugging argument. The scenario warning's Open Build Profiles button opens the build profile settings.

Run the scenario and iterate

When you start Play mode through the scenario, it validates the project and prepares the selected target before the instances run. For a local target, it starts the local Cloud Code server. For a remote target, it deploys only changed modules. It then waits after the last upload completes before the instances run, so the Cloud Code invokers have time to download the updated code.
To run and update your scenario:
  1. With the scenario selected in the toolbar, select Play.
  2. In the toolbar, select the scenario dropdown, then select Active Play Mode Window.
  3. In the Active Scenario window, check the server status in the Cloud Code Server section.
  4. After changing local Cloud Code modules, exit Play mode and wait for
    Local Cloud Code server reloaded
    in the Console before running the scenario again.
The local server remains running between runs. It stops when you select another scenario, run the scenario with Deploy Target set to Remote, or quit the Editor. You can change Deploy Target between runs without restarting the Editor instances. Module changes made during Play mode reach the local server when you exit Play mode.
For more information about managing the local server, refer to Run a local Cloud Code server.

Additional resources