Microservice UPM¶
Sharing a Microservice with Unity via UPM
Dependencies¶
Before you can use Distribute a Microservice with UPM, you need to complete the Getting-Started Guide. That means having Dotnet 10 installed, and getting the Beam CLI.
You can confirm you have everything installed checking the versions of the tools.
You also need to have a local .beamable workspace with a Beamable
Standalone Microservice. As a reminder, you can create one quickly using the commands below.
Steps¶
Standalone Microservice projects can be distributed as Unity Package Manager (UPM) packages, which allows downstream Unity projects to re-use an existing Microservice.
However, there are several configuration steps required in the Standalone Microservice project.
Preparing the Microservice¶
Follow these steps to convert an existing Standalone Microservice into a UPM compatible Microservice.
- Rename "services" folder to "services~"
- Modify the
.slnfile to mirror the folder name change. - Create a local
Assetsfolder next to the.beamablefolder - Create a
Runtimefolder and aRuntime/Clientfolder next to the.beamablefolder - Create a file in the
.beamablefolder calledlinked-projects.json,
So far, your folder structure should at least have these files.
/Project
/.beamable
linked-projects.json
/Assets
/Runtime
/Client
/services~
/Service
Service.cs
Service.csproj
Program.cs
Dockerfile
- In the
Runtime/Clientfolder, create a file calledService.Client. asmdef(replace"Service"with your service name), and paste the following,Make sure to replace{ "references":[ "Beamable.Platform", "Unity.Beamable", "Unity.Beamable.Runtime.Common", "Unity.Beamable.Server.Runtime", "Unity.Beamable.Server.Runtime.Common", "Unity.Beamable.Customer.Common" ], "name": "Service.Client", "autoReferenced": true }"Service"in the"name"field with your service name. - Now you are ready to generate the client code. To do this, run the
following command AFTER building your Microservice. This command
should be run from the
/services~/Servicefolder. - You need to create a
package.jsonfile. Place it next to the/Assetsfolder in the Microservice project.
Finally, your project structure should look similar to this,
So far, your folder structure should at least have these files.
/Project
package.json
/.beamable
linked-projects.json
/Assets
/Runtime
/Client
ServiceClient.cs
Service.Client.asmdef
/services~
/Service
Service.cs
Service.csproj
Program.cs
Dockerfile
Preparing the Unity Project¶
Now that the Microservice is ready, in order to import it into a Unity project as a UPM package, follow these steps.
- Ensure that the Unity project is referencing Beamable's packages.
At least Beamable version
com.beamableandcom.beamable.server2.1.3 is required. - In Unity Package Manager, add a package from disk, and select the path to
your created
package.jsonfrom the previous steps. - Modify the
.beamable/additional-project-paths.jsonfile in the Unity project and add the path to the UPM project folder.