This repository contains the Unity client for the Enjin Platform sample game. It's a simple farming game designed to demonstrate how to integrate Enjin's NFT technology into a Unity project. 🧑🌾
This client communicates with a C# game server (ASP.NET Core, built on the Enjin Platform C# SDK v3) to handle all blockchain-related actions like minting, melting, reading players' wallets, and transferring NFTs.
This guide will get you up and running quickly.
- ✅ Unity Hub with Unity Editor version
6000.3.16f1 - ✅ Git
Follow the setup instructions in the game server repository. The server will start on http://localhost:3000 by default, create its managed daemon wallet, and create a Collection on first run. The Collection ID is persisted in the server's state.json and exposed via GET /api/setup/collection-id.
You no longer need to copy the Collection ID by hand — the Unity client pulls it from the server in Step 4.
Open a terminal or command prompt and run:
git clone https://github.com/enjin/platform-sample-game-client-unity.git- Open Unity Hub.
- Click
Add->Add project from disk. - Select the cloned
platform-sample-game-client-unityfolder. - Open the project in the Unity Editor.
The project pulls in the Enjin Platform Unity SDK as a UPM package over git. Packages/manifest.json references it as:
"io.enjin.platform-sdk": "https://github.com/enjin/platform-unity-sdk.git#v3.0.2"
Unity will fetch and cache the package on first project open.
Note: the sample game itself does not use the Enjin Platform SDK. All blockchain actions (mint, melt, transfer, wallet reads) go through the C# game server's REST API — the client's
EnjinApiServicesimply makes HTTP calls. The SDK lives on the server, where the API key is kept safe and away from the client.The SDK UPM package above is pulled in only for the optional
EnjinSdkSmokeharness (see below), which exercises the SDK directly for verification. If your goal is to learn how to integrate Enjin into a game, the pattern to study here is game client → your server → Enjin Platform SDK, not calling the SDK from the client. (Curious what the UPM package is for and why this game doesn't use it? See What is the UPM package for, and when should you use it? at the end.)
The three EnjinItem assets shipped with the client (GemGreen, GoldCoin, GoldCoinBlue under Assets/Enjin Integration/Scripts/Data/Items) ship with a placeholder Collection ID and must be stamped with the value created by your running server before the game will recognise minted tokens.
With the server running:
- In the Unity Editor menu bar, choose Enjin → Stamp Collection ID onto EnjinItem Assets.
- Confirm the server host in the dialog (defaults to
http://localhost:3000, persisted inEditorPrefsbetween runs). - The editor will call
GET /api/setup/collection-id, write the returned value into everyEnjinItemasset'sCollection Idfield, save the assets, and report how many were updated.
Re-run this menu item any time you point the client at a different server, or after resetting a server's state.json (which generates a new Collection).
If the menu item fails (for example, the server is unreachable from the Editor or you'd rather copy/paste), you can stamp the assets by hand:
- Get the Collection ID. With the server running, either open
http://localhost:3000/api/setup/collection-idin a browser,curlit, or read thecollectionIdvalue out of the server'sstate.json. - In Unity's
Projectwindow, navigate toAssets/Enjin Integration/Scripts/Data/Items. - Select each of
GemGreen,GoldCoin, andGoldCoinBluein turn. In the Inspector, paste the Collection ID into the Collection Id field. - Save the project (
Ctrl/Cmd+S).
Note: If you run the server on a non-default host or port, also select the
EnjinManagerprefab inAssets/Enjin Integration/Prefabs/and update theHostfield on theEnjin API Servicecomponent. The default ishttp://localhost:3000.
Make sure the game server is still running in the background.
- In the Unity Editor's
Projectwindow, navigate toAssets/HappyHarvest/Scenes. - Double-click the
MainMenuscene and press Play, then click Start to enter the farm. (You can also openFarm_Outdoordirectly, but starting fromMainMenuensures theEnjinManagerprefab is initialised.)
Once the game is running:
- Login: Click the Menu button (top-right), then Login. Enter any email and password to register a new player. This automatically creates a managed wallet for you on the platform.
- Move: Use the W, A, S, D keys to move your character.
- Harvest: Walk up to a crop and click on it to harvest it.
- Collect NFTs: Keep harvesting until a resource item (gem or coin) appears. Click on the item to collect it — this mints the item as an NFT to your player's wallet.
- View Your NFTs: Click the Backpack button (top-right) to see your collected NFTs. From there you can Melt them or Send them to another wallet.
Two standalone test scenes are included for verifying the integration without playing the full game:
Assets/GameServerSmoke/— exercises the client'sEnjinApiServiceend-to-end against a running game server (register/login, mint, melt, transfer, balance queries). Open via Enjin → Open Game Server Smoke Scene and press Play.Assets/EnjinSdkSmoke/— calls the Enjin Platform directly through the Unity SDK UPM package, against the canary GraphQL endpoint and bypassing the game server. Useful for confirming the UPM package works end-to-end inside Unity, or telling whether a problem is in the package/Platform or in your server.
See the README.md inside each folder for details.
| Menu Path | When to Use |
|---|---|
| Enjin → Stamp Collection ID onto EnjinItem Assets | Required before first play, and any time you change which server you connect to. |
| Enjin → Open Game Server Smoke Scene | Optional. Build/open the standalone scene that tests the client against the game server. |
The Enjin UPM package (io.enjin.platform-sdk, added in Step 3) lets your Unity code talk to the Enjin Platform directly. Add it through the Package Manager and you can run Platform queries and mutations — mint, melt, transfer, wallet and balance reads — straight from C# in your game, with no backend of your own.
Security. Every Platform call is authenticated with your Platform API token. If your Unity game calls the Platform directly, that token has to be embedded in the build you hand to players — and a token shipped inside a distributed app can be extracted and used to act as your account (mint, transfer, drain funds).
To avoid that, this sample keeps the token on a small game server it controls. The Unity client only ever calls that server, and the server makes the Platform calls on its behalf. The token never leaves your infrastructure. That client→server split is the recommended pattern for a game you actually publish.
Use the UPM package directly when your token won't end up in untrusted hands:
- Prototyping and learning — wire up Platform calls from the Editor to see how things work before building any backend. (The optional
EnjinSdkSmokescene in this project does exactly this.) - Internal or trusted tools — an in-house Unity Editor utility or admin tool that never leaves your team.
- Hackathons and demos — where shipping to untrusted users isn't a concern.
Use a server in between (what this sample demonstrates) for anything you distribute to players:
- The API token stays on your server and never ships in the build.
- The server can enforce its own rules — authentication, validation, rate limiting, anti-cheat — before it ever touches the Platform.
- The client only knows about your API, never your Platform credentials.
Rule of thumb: if players will run your build, keep the token behind a server. The UPM package is the quick path for prototypes and trusted tools; the server pattern is the safe path for shipping games.
For more in-depth information about the Enjin Platform and its features, please refer to the official documentation: