Cloud Code C# modules
Deploy reusable, server authoritative C# libraries that allow multiple entry points and generate type-safe client bindings.
Read time 5 minutesLast updated 3 days ago
Modules are C# libraries that the Cloud Code service can run to give you reusable server authoritative code. Unlike Cloud Code scripts, modules allow for multiple entry points and easier code reuse within the module.
You can generate bindings for your modules from the Unity Editor to ensure that the 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.
Benefits of C# modules
C# modules have the following benefits:
- Modules support code reuse, which improves the maintainability of your project. Like any C# project, you can share classes and logic between endpoints in the same module.
- Module endpoints deploy together, which allows your data models to always be in sync.
- The Unity Editor can call modules in a type safe way, which helps to prevent errors with misspelled method names and incorrect data parameters.
- Modules support an in-memory cache, which can speed up response times and reduce costs.
Authoring method | Description |
|---|---|
| Unity Editor | Create, compile, and deploy modules directly in the Editor as Unity Cloud Code modules ( |
| Module reference | Link a C# module reference file to a separate module solution in the Editor. |
| UGS CLI | Deploy and manage modules from the command line. |
| REST API | Create, deploy, and manage modules through the Cloud Code REST API. |
| Unity Dashboard | Preview a list of deployed modules. |
Typical workflow
The following process details a typical development cycle:
- Create a C# library project. Create a solution in the Unity Editor or use the UGS CLI to create a new module project.
- Write the code. Use the Cloud Code C# service SDKs to integrate with other Unity services. Use the HTTP client to integrate with external services. For games that need persistent state, use Stateful Cloud Code.
- 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.
- Deploy the module. Deploy the project via the Deployment window in the Unity Editor or UGS CLI or to make it available within Cloud Code.
- 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.
Getting started
Learn the basics of creating and running modules.
Topic | Description |
|---|---|
| Create a module | Get started with modules. |
| Module structure | Learn about the structure of a module project. |
| Develop modules | Learn how to develop modules using different authoring methods. |
| Run modules | Learn how to run modules from Unity Runtime, using REST API |
| Error handling | Learn how handle errors in your modules. |
| Logging | Learn how to use logging to debug your module. |
| Limits | Learn about the limits of Cloud Code modules. |
| Cost | Learn about the cost of Cloud Code modules. |
Development essentials
Learn how to structure your modules. Modules support dependency injection, DTOs, and custom serialization to make your development easier.
Topic | Description |
|---|---|
| Module structure | Learn about the structure of a module project. |
| Dependency injection | Decouple dependencies in your code. |
| Unit tests | Write unit tests for your module. |
| Custom serialization | Learn how to use custom serialization using |
| Batch requests | Batch requests. |
| In-memory cache | Cache slow-changing data between module endpoints to reduce latency. |
| Run a local Cloud Code server | Run a Cloud Code server on your local machine to iterate on and debug modules. |
Stateful Cloud Code
By default, Cloud Code is stateless. For games that require persistent state, such as card, puzzle, and idle games, Stateful Cloud Code uses scopes to retain data across module function calls.
Topic | Description |
|---|---|
| State scopes | Retain state for individual players or multiplayer sessions using scopes. |
| State serialization | Control how the runtime serializes and persists your module's scoped state. |
| Timers | Schedule delayed Cloud Code function calls for cooldowns, turn timers, and more. |
| Function access control | Control who can invoke individual functions using an access parameter. |
| Turn change notification patterns | Notify clients of turn changes in synchronous and asynchronous multiplayer games. |
Automate deployment
To streamline the development and deployment of your modules, you can automate the process.
Topic | Description |
|---|---|
| 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. |
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 packages, or you can use a HTTP client.
NuGetTopic | Description |
|---|---|
| Authentication | Learn how to authenticate your game client with Cloud Code. |
| Service and access token support | Learn which UGS services and access tokens Cloud Code supports. |
| Available libraries | Find the available UGS SDKs included with Cloud Code modules. |
| Access control | Learn how to control access and prevent unwanted usage. |
| Integrate with Unity Services | Learn about connecting Cloud Code to other Unity services. |
| Integrate with external services | Learn how to integrate with external services. |
| Interact with cross-player data | Learn how to access and update data for other players. |
| Send push messages to players | Learn how to send push messages to players. |
| Triggers | Learn how to use triggers to run your modules on a schedule, or in response to events. |
Advanced configuration
If you need a more in-depth configuration for your module, you can use the following guides.
Topic | Description |
|---|---|
| Manual workflow | Learn how to manually create, package, and deploy your module. |
| Package code | Learn how to package your module code into a |
| Automate local deployment using the project file | Automate the deployment of your module using the project file. |
| Data transfer objects | Learn how to use data transfer objects to ensure that all data transferred between the Cloud Code client and your game use the same format. |