Sharing Microservices between Projects

The primary way to use Microservices in Unity is to create a new service for each Unity project. However, there are several ways to share Microservice functionality between multiple Unity projects using Beamable.


Unity Package Manager

You can create a custom Unity Package by following Unity's documentation, https://docs.unity3d.com/Manual/CustomPackages.html. A custom package can include a Microservice. When downstream Unity projects import the package, they will have readonly access to the Microservice.

After you have made a custom Unity project, follow these steps to add a Microservice to the package.

  1. Create a hidden folder in the package called BeamableServices~. The ~ character is a special character in Unity that instructs the compiler and asset database to completely ignore the folder. This folder will contain the Microservice and Unity should not attempt to compile the .cs code.
  2. Move an existing Microservice folder into the new BeamableServices~ folder, or create a new service in that folder directly with the CLI's Project New Servicecommand.
  3. Create a custom Assembly definition in your package for the auto-generated client. Follow the Calling Microservices from Unity steps to create an Assembly definition that ends with your <name>.Client.asmdef. The Unity Package will contain the auto-generated client itself, and downstream projects will not attempt to regenerate the client.

As you develop your Microservice in the /Packages folder, it will act like any Microservice in your /Assets folder. However, when a downstream project imports the custom Unity package, it will appear as "Read Only".


Nuget

An alternative approach to sharing Microservice capabilities is to package and distribute your server code as a composable Nuget package. Multiple Unity projects will need to create their own Microservice projects in the project's /Assets folder; and simply use Nuget to reference the custom code from within the Microservice itself.

An advantage to this approach is that the downstream projects can modify the Microservice code to extend or modify the code as need be.