Integrate Unity Gaming Services (UGS) in Unity
Learn how to integrate UGS backend and Openfort with your game
Overview#
This is a sample project to showcase the Openfort integration with Unity Gaming Services, a complete service ecosystem for Unity live games.
The sample includes:
-
A .NET Core project with Cloud Code C# modules that implement Openfort C# SDK methods. Hosted in UGS.
-
A Unity sample game that connects to
ugs-backend
through Cloud Code. It uses Openfort Unity SDK to deserialize its responses.
The sample uses Unity Authentication to sign in as a new anonymous player. It then creates an Openfort player and a custodial account using Openfort and it links it to the Unity player. Then the player can frictionlessly mint an NFT.
Application Workflow#
Prerequisites#
-
Get started with Openfort
-
Get started with UGS
Setup Openfort dashboard#
-
This sample requires a contract to run. We use 0xbed6a05ce8719bc00db1cc81a814192c82be1bb1 (NFT contract deployed in 80002 Amoy). You can use this for the guide:
-
We aim to cover gas fees for users. Set a new gas policy:
Now, add a rule so our contract uses this policy:
Set up ugs-backend
#
-
Set Openfort dashboard variables#
Open the solution with your preferred IDE, open
SingletonModule.cs
and fill in these variables: -
Package Code#
Follow the official documentation steps.
-
Deploy to UGS#
Follow the official documentation steps.
Set up unity-client
#
Follow the official documentation steps to link the unity-client
to your UGS Project ID.
Test in Editor#
Play the Main scene and click Sign in button. After some authentication-related logs, this panel should appear:
Select Mint. After a brief period, you should see a representation of your newly minted NFT:
In the Openfort Players dashboard, a new player entry should be visible. On selecting this player:
You'll notice that a mint
transaction has been successfully processed:
Additionally, by choosing your Amoy Account and viewing NFT Transfers, the transaction is further confirmed:
Keep in mind that the sample is designed so a player can mint only once. By default, UGS Authentication will use the same player per device. If you want to sign in with a new player check the Clear Session Token in AuthController:
Conclusion#
Upon completing the above steps, your Unity game will be fully integrated with Openfort and UGS. Always remember to test every feature before deploying to guarantee a flawless player experience.
For a deeper understanding of the underlying processes, check out the tutorial video.
Get support#
If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.
If you have questions, or comments, or need help with code, we're here to help:
- on Twitter at https://twitter.com/openfortxyz
- on Discord: https://discord.com/invite/t7x7hwkJF4
- by email: support+youtube@openfort.xyz