Cloud Code C# modules

C# 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 transferred between the Cloud Code client and your game use the same format.

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.
  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 the 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.
Create a C# moduleLearn about the different steps required to create a C# module project.
Dependency injectionLearn how to decouple dependencies in your code and unit testing easier.
Unit testing modulesIdentify and fix issues early in the development process using unit testing.
Service SDKsLearn about connecting Cloud Code to other Unity services.
Execution contextUse the IExecutionContext interface to provide you with extra information about the current call.