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.
Note: 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 API key and Platform SDK live on the server, safely away from the client. The pattern to study here is game client → your server → Enjin Platform, not calling the Platform directly from the client (which would ship your API token inside the build).
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.
A standalone test scene is 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.
See the README.md inside the 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. |
Security. Every Platform call is authenticated with your Platform API token. If your Unity game called the Platform directly, that token would have 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. The server can also enforce its own rules — authentication, validation, rate limiting, anti-cheat — before it ever touches the Platform.
Rule of thumb: if players will run your build, keep the token behind a server. That client→server split is the recommended pattern for a game you actually publish.
For more in-depth information about the Enjin Platform and its features, please refer to the official documentation: