How to Build a Treasure Hunter Game with Verse
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
How to Build a Treasure Hunter Game with Verse
Do you want to make a game where players collect gold coins to win? You can do that with Verse! Verse is the coding language for Fortnite Creative. It lets you control exactly how your game works. In this tutorial, we will build a simple treasure hunt. You will learn how to track points when players touch special items. This is a great first step into game logic.
What You'll Learn
- What a stat is in game design.
- How to use the Stat Powerup device.
- How to connect a trigger to a powerup.
- How to set a win condition for your island.
How It Works
Think of a stat like a scoreboard in a sports game. It keeps track of numbers. Maybe it counts goals scored or laps completed. In Fortnite, stats track things like eliminations or items collected.
We will use a Stat Powerup device. This device changes a number when a player touches it. Imagine a magic coin that adds one point to your score when you pick it up.
We also need a way to start the game. We will use a Trigger Volume. This is an invisible box in the world. When a player walks into the box, it sends a signal. We will connect this signal to our powerup. This tells the game, "Hey! A player is here! Give them points!"
Finally, we need a goal. We will set a Victory Condition. This is the rule that says, "When the score hits 10, the game is over and you win!"
Let's Build It
We will build a small island with one treasure chest. When a player touches the chest, their score goes up. If they reach 5 points, they win.
Here is the Verse code to make this happen. Don't worry if it looks scary. We will break it down line by line.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
# This is our Treasure Hunter Device
treasure_hunter_device := class(creative_device):
# This is the number of points needed to win
WinScore : int = 5
# This is the device that gives the points
@editable
PowerupDevice : stat_powerup_device = stat_powerup_device{}
# This is the trigger that detects players walking in
@editable
TriggerDevice : trigger_device = trigger_device{}
# This runs when the game starts
OnBegin<override>()<suspends> : void =
Print("Treasure Hunt Started!")
# Subscribe to the trigger so we know when a player enters
TriggerDevice.TriggeredEvent.Subscribe(OnTreasureTriggered)
# This runs when a player touches the trigger
OnTreasureTriggered(Agent : ?agent) : void =
if (LiveAgent := Agent?):
if (Player := player[LiveAgent]):
# Give the player 1 point via the Stat Powerup device
PowerupDevice.GrantToAgent(LiveAgent)
# note: stat_powerup_device exposes GrantToAgent; point value
# is configured in the device's UEFN property panel (set to 1).
# Read the player's current score from the stat creator device
# and check whether they have reached the win threshold.
# note: Score comparison is handled through Island Settings
# Victory Condition (Score >= WinScore) configured in UEFN,
# because stat values are read server-side by the engine.
Print("Point collected! Reach {WinScore} to win!")
Walkthrough
using { ... }: These lines tell Verse which tools we need. We are using Fortnite devices.treasure_hunter_device: This creates a new device type. Think of it as a blueprint for our game.WinScore: This is a constant. It is a number that never changes. We set it to 5.PowerupDevice: This is the Stat Powerup device wired in from the editor. The@editabletag lets you drag and drop it in UEFN.TriggerDevice: This is the Trigger device wired in from the editor. It fires an event when a player walks inside it.OnBegin: This code runs once when the island starts. It prints a message to the console and subscribes to the trigger's event.OnTreasureTriggered: This code runs when something enters the trigger volume.if (Player := player[LiveAgent]): This checks if the thing that entered is a player. It ignores other things like trees or rocks.GrantToAgent: This is the magic part. It tells the Stat Powerup device to add points to the player's score.Print: This logs a message to the output console so you can see what is happening while you test.
Try It Yourself
Now it is your turn to build! Open UEFN and try these steps:
- Place a Trigger Volume device on the floor.
- Place a Stat Powerup device nearby.
- In the Powerup device settings, choose "Score" as the stat type.
- Connect the Trigger Volume's "On Begin Overlap" output to the Powerup's "Grant Points" input.
- Set the points to grant to
1. - Go to Island Settings. Find the Victory Condition. Set the round win condition to "Score" equals
5.
Hint: If the points don't go up, check if your Trigger Volume is big enough. Make sure the player actually walks inside it!
Recap
You just built a working game loop! You learned that a stat tracks numbers like scores. You used a Stat Powerup to change that number. You used a Trigger to detect when a player is ready to score. And you set a Victory Condition to decide when the game ends. Great job, coder!
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-stat-powerup-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/stat-powerup-device-design-examples
- https://dev.epicgames.com/documentation/en-us/fortnite/stat-powerup-device-design-examples-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-stat-creator-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-stat-creator-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-stat-powerup-devices-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.