Cloud Code C# modules

Modules are C# libraries that the Cloud Code service can run to give you reusable server authoritative code. Unlike single scripts, these modules allow for multiple entry points and easier code reuse within the module.

You can also create a main library and a data transfer object (DTO) library that both Cloud Code and your game can use to ensure that all data you transfer between the Cloud Code client and your game use the same format.

You can call modules from games built with Unity, or from any other client or server.

Authoring methodDescription
Unity Cloud DashboardUse the Unity Cloud Dashboard preview a list of deployed modules. You can access other Unity Gaming Services from the same place, such as Remote Config.
Unity EditorUse the Unity Editor to create and deploy modules using the deployment window, automate your workflow and deploy Cloud Code alongside other Unity services.
Unity Gaming Services CLIUse the CLI to deploy and manage modules from the command line. Deploy multiple Unity service configurations at once, and integrate with CI/CD.

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.

Typical workflow

The following process details a typical development cycle:

  1. Create a C# library project. Create the module project in the IDE that you're already familiar with for C# code.
  2. Write the code. Integrate with other Unity services by using the Cloud Code C# service SDKs. Integrate with external services by using the HTTP client.
  3. Test and debug. Create a unit test project for your module to validate that everything works as intended, or deploy the library on a development environment to test it with real user data.
  4. Deploy the module. Deploy the library via UGS CLI to make it available within Cloud Code.
  5. Integrate the module with your project. Import the Cloud Code SDK into your game and use one of the provided methods to call your script.

Fundamental concepts

Learn about the fundamental concepts of Cloud Code modules.

TopicDescription
Create a module project.Learn how to create a module.
Module structure.Learn about the structure of a module project.
Package code.Learn how to package your module code into a .ccm file for deployment.
Write modules.Learn how to write modules using the UGS CLI or REST API.
Run modules.Learn how to run modules from Unity runtime, using REST API or from a Multiplay server.
Error handlingLearn how handle errors in your modules.
LoggingLearn how to use logging to debug your module.

Improve your workflow

To streamline the development and deployment of your modules, you can automate the process.

TopicDescription
Integrate with CI/CD.Integrate the deployment of your module with your CI/CD pipeline.
Automate local deployment.Automate the deployment of your module to the Cloud Code service.

Development essentials

Modules support dependency injection, DTOs, and custom serialization to make your development easier.

TopicDescription
Dependency injectionLearn how to decouple dependencies in your code.
Unit testsLearn how to write unit tests for your module.
Data transfer objectsLearn how to use data transfer objects to ensure that all data transferred between the Cloud Code client and your game use the same format.
Custom serializationLearn how to use custom serialization using Newtonsoft.Jsonproperties.

Integrate further

You can integrate modules with other Unity Gaming Services and any external services, and access cross-player data.

To integrate with other services using their C# SDKs, you can install NuGet packages, or you can use a HTTP client.

TopicDescription
AuthenticationLearn how to authenticate your game client with Cloud Code.
Service and access token supportLearn how to use service and access tokens to authenticate your modules.
Available librariesFind the available UGS SDKs included with Cloud Code modules.
Access controlLearn how to control access and prevent unwanted usage.
Integrate with Unity ServicesLearn about connecting Cloud Code to other Unity services.
Integrate with external servicesLearn how to integrate with external services.
Interact with cross-player dataLearn how to access and update data for other players.
Send push messages to playersLearn how to send push messages to players.
TriggersLearn how to use triggers to automate server side actions.