Hiro Challenges Sample Project
The official sample project for the Hiro Challenges system. This project demonstrates how to create, join, and manage challenges using the Hiro SDK in Unity. It’s built with minimal boilerplate so you can easily copy the code into your own game.
Features
- Challenge friends to different game modes, competing for the best score or time.
- Set rules like max score attempts, duration, and public/private visibility.
- Browse and join public challenges, invite friends to ongoing challenges, and view the status of active challenges.
- Submit scores and track rankings on real-time leaderboards.
- Claim rewards when a challenge ends.
- Built-in account switcher for quick multi-account testing.
Installation
The installation steps and resulting folder structure will vary depending on if you downloaded the project from Github or the Unity Asset Store.
For optimal display, set your game resolution in the Unity Editor to 1920x1080
- Clone or download the Sample Projects repository onto your machine.
- From the Unity Hub, click Add -> Add project from disk and choose the top-level UnityHiroChallenges folder.
- You may see several warnings about Editor version incompatibility. Feel free to ignore these messages as long as you're on Unity 6 or greater. Continue on until you arrive at the main Editor UI.
- Open the main scene by navigating to Assets -> UnityHiroChallenges -> Scenes -> Main.
- Hit Play.
The project connects to our demo server so you can see the features in action immediately.
Note: The server is reset on the 1st of every month at 00:00 UTC.
Folder structure
Assets/
├── UnityHiroChallenges/
├── HeroicUI/ # UI assets and styling
├── Scripts/ # Main project code
├── UI/ # UI Builder files
└── ... # Everything else
├── Packages/ # Contains the Nakama Unity package
Code overview #
The project uses Hiro’s systems-based architecture, which provides an opinionated structure for building games with pre-configured systems.
Coordinator (HiroChallengesCoordinator.cs)
#
Extends the HiroCoordinator class to set up the Nakama connection and initialize Hiro systems. It handles system lifecycle and authentication before your game logic runs. Learn more about Hiro’s deterministic startup.
| |
API reference: Hiro Initialization
Controller (ChallengesController.cs)
#
Coordinates between the UI and Hiro Challenges API. Subscribes to view events, manages challenge state, and executes game logic by calling the Challenges system.
Challenge templates (game modes)
| |
Challenge discovery
| |
Challenge lifecycle
| |
Scoring and rewards
| |
API reference: Challenges
Challenges view (ChallengesView.cs)
#
Manages the main UI layer for the challenges screen, including lists, modals, and buttons. Provides an event-based interface that the controller subscribes to for responding to player interaction.
Challenge view (ChallengeView.cs)
#
Binds challenge data to UI elements for the challenges list. Displays name, category, participant count, status (pending/active/ended), and end time.
Participant view (ChallengeParticipantView.cs)
#
Binds participant score data to UI elements. Displays username, score, subscore, rank, and submission count (e.g., “2/3” means 2 scores submitted out of 3 allowed).
Account Switcher
The Account Switcher lets you explore the project as different players without managing multiple builds. Use it to view challenges, create challenges, and submit scores from different accounts.
How to use:
- Open the Account Switcher panel (Tools > Nakama > Account Switcher).
- Select different accounts from the dropdown to switch between up to four test users.
- Each account is automatically created the first time you select it.
Key points:
- Only works while your game is running in Play mode.
- Usernames will display in the panel after switching to an account for the first time.
Setting up your own Nakama server with Hiro
While this project works with our demo server, you'll want to set up your own Nakama and Hiro instance to customize the features and configurations.
Prerequisites
Before you can set up Hiro, you'll need to:
- Install Nakama: Follow the Nakama installation guide to get Nakama running with Docker.
- Obtain Hiro: Hiro is available to licensed users. Contact us to obtain your license.
- Install Hiro: Once you have your license key, follow the Hiro installation guide.
Configure Hiro
This sample project ships with specific Hiro system configurations on the server. You can view the exact configuration files used in our demo server here: Demo server configurations.
Copy the JSON files to your server (such as inside a definitions directory)
and update main.go to initialize the required Hiro systems
according to the
installation guide
or
view the example on Github.
Connect this Unity project to your server
After installing Nakama and Hiro and running it locally with the appropriate configurations, edit these settings in the Unity Editor to connect to your server:
- Select the main coordinator component from the scene hierarchy panel.
- Open the Inspector tab.
- Look for the field inputs under Nakama Settings and replace
them with the following:
- Scheme:
http - Host:
127.0.0.1 - Port:
7350 - Server Key:
defaultkey
- Scheme:
Additional resources
