Documentation

Cloud Code

Version: 3.0.0  
Unity 6.7 (6000.7)+
Open Unity Dashboard

Cloud Code

Version: 3.0.0  
Unity 6.7 (6000.7)+

Shared rules library

Share rule logic between your client and your CloudBehaviour by putting it in a shared assembly.
Read time 2 minutesLast updated 12 days ago

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.
When synchronized rule outcomes can no longer represent your rules, share your rule logic directly instead of re-implementing it on both sides. Put the shared logic in its own assembly, and reference that assembly from both your client assembly and your CloudBehaviour's cloud assembly. On deploy, the build bundles the shared assembly into your Cloud Code module automatically, so you write the rule once.
A model type that crosses the client boundary through the client bindings carries only data. A type in a shared assembly keeps its methods on both sides, because the client references the real assembly instead of a generated, data-only stub.

Set up a shared rules library

To set up a shared rules library:
  1. Create an assembly definition for your shared code, separate from your cloud and client assemblies.
  2. In the Inspector window of the shared assembly, enable No Engine References. This setting is required. The cloud assembly can't reference
    UnityEngine
    types, so the shared assembly can't either. If your cloud script uses a type from an assembly that references the Unity Engine or the Unity Editor, the build fails with
    CCSG130
    .
  3. Add the shared assembly to the Assembly Definition References list of both your cloud assembly and your client assembly.
  4. Put your shared rule logic and data types in the shared assembly, using plain C#.
After you add the shared assembly to both Assembly Definition References lists, your cloud and client code can reference the same types directly.
The following example shows a minimal shared assembly definition:
{ "name": "MyGameShared", "noEngineReferences": true}
The following shared type carries a real method, not only data, because both your cloud and client assemblies reference it directly:
namespace MyGame.Shared{ public class MoveResult { public bool WasLegal; public int Column; public string Describe() => WasLegal ? $"Placed at column {Column}" : "Move rejected"; }}
Both your cloud class and your client code can now call
Describe()
, and they run the same source code instead of two separate implementations. Results are identical as long as the code doesn't depend on runtime-specific behavior, such as culture settings or floating-point precision.

Bundle referenced assemblies

When you deploy your module, the build bundles your shared assembly and everything it references into the module, the same way it bundles your cloud assembly's own references. To bundle a precompiled DLL, enable Override References on the shared assembly and add the DLL to its Assembly References list. The build doesn't bundle DLLs that Unity references automatically.

Additional resources