Build a Secret Hide-and-Seek Game
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.
Build a Secret Hide-and-Seek Game
Do you like playing hide-and-seek? You know the feeling. You count to ten while your friends run to find the best spot. Then, you hold your breath and stay super still! In this tutorial, we will build a digital hide-and-seek game. You will create a "Seeker" that can see players. You will also create a "Hider" who needs to stay hidden. It is like a real game, but on your own island.
What You'll Learn
- How to make a device that acts like eyes.
- How to use a timer to turn those eyes on and off.
- How to give players a message when they are found.
- How to use the Scene Graph to organize your game parts.
How It Works
Imagine you are playing hide-and-seek in a big house. The seeker stands in the hallway. They count. Then they turn around. If they see you, they shout, "I see you!" That is how our game works.
We need a special device called a Perception Trigger. Think of this device as the Seeker's eyes. It has a special "cone of vision." If a player walks into that cone, the device knows. It is like a security camera that only looks in one direction.
But wait! If the Seeker sees you all the time, it is not fun. You can never hide. So, we need a Timer. The Timer is like a clock. It tells the Seeker's eyes to blink. The eyes open for a few seconds. Then they close. Then they open again. This gives you a chance to run behind a box or into a closet.
We also need a Damage Volume. This is an invisible box on the floor. When the Seeker's eyes are open and they see you, this box hurts you. It is not real pain. It just means you lost that round.
Finally, we use a HUD Message. HUD stands for "Heads-Up Display." It is the text you see on your screen. When you get found, a message will pop up saying, "Found You!"
Let's Build It
We will write some code to make this happen. This code uses a concept called the Scene Graph. Think of the Scene Graph like a family tree for your game. The main game is the parent. The Seeker and the Hiders are the children. This helps the code know where everything is.
Here is the code for our Seeker. Copy this into a Verse script in your island.
# This is our main game script.
# It is like the brain of the Seeker.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# We create a "class". This is like a box for our code.
# It must be placed in the editor as a Verse device.
hide_and_seek_game := class(creative_device):
# This is the "Perception Trigger" device.
# Drag it from the editor into this property slot.
@editable
PerceptionTrigger : perception_trigger_device = perception_trigger_device{}
# This is the "Timer" device.
# It controls when the eyes open and close.
@editable
TimerDevice : timer_device = timer_device{}
# This is the "Damage Volume".
# It is the invisible box that catches players.
@editable
DamageVolume : damage_volume_device = damage_volume_device{}
# We track whether the seeker's eyes are open.
# false means the eyes start closed.
var EyesOpen : logic = false
# This function runs when the game starts.
OnBegin<override>()<suspends> : void =
# Subscribe to the timer's completion event.
# When the timer finishes, call OnTimerFinished.
TimerDevice.SuccessEvent.Subscribe(OnTimerFinished)
# Subscribe to the perception trigger's triggered event.
# When a player is spotted, call OnPlayerSeen.
PerceptionTrigger.TriggeredEvent.Subscribe(OnPlayerSeen)
# Turn the perception trigger off at the start.
# The eyes begin closed so players have time to hide.
PerceptionTrigger.Disable()
# Start the timer for 5 seconds.
# It will wait before the seeker first opens its eyes.
TimerDevice.Start()
# This function runs when the timer finishes.
OnTimerFinished(Agent : ?agent) : void =
# Toggle the seeker's eyes.
# If eyes are open, close them.
# If eyes are closed, open them.
if (EyesOpen?):
set EyesOpen = false
PerceptionTrigger.Disable()
else:
set EyesOpen = true
PerceptionTrigger.Enable()
# Restart the timer to keep the blinking loop going.
TimerDevice.Start()
# This function runs when the seeker sees a player.
OnPlayerSeen(Agent : agent) : void =
# Only deal damage if the eyes are currently open.
if (EyesOpen?):
# Enable the damage volume so it hurts players inside its volume.
# damage_volume_device has no per-player Activate API; Enable()
# triggers it for anyone already inside its volume.
DamageVolume.Enable()```
### Walkthrough of the Code
1. **`PerceptionTrigger`**: This line connects our code to the Perception Trigger device in the editor. It is like giving the code a remote control.
2. **`TimerDevice`**: This connects to the Timer device. It tells the code when to change the seeker's state.
3. **`OnBegin()`**: This is the first thing that happens. It starts the clock and wires up the events.
4. **`OnTimerFinished()`**: This is the magic part. It flips the switch. If the seeker was looking, they stop looking. If they were not looking, they start looking. Then it restarts the clock. This makes the eyes blink!
5. **`OnPlayerSeen()`**: This checks if the seeker is actually looking right now. If yes, it triggers the damage volume.
## Try It Yourself
Now it is your turn to build the island! Follow these steps:
1. Place a **Perception Trigger** in the center of your room. Point it at the floor.
2. Place a **Timer** device next to it.
3. Place a **Damage Volume** on the floor where the Perception Trigger is pointing.
4. Link them up in the device graph. Connect the Timer to the Perception Trigger. Connect the Perception Trigger to the Damage Volume.
5. Test it! Play as a hider. Run into the cone when the eyes are open. See if you get found!
**Hint:** If the seeker never finds you, check if the Timer is set to a short time, like 2 seconds. If it is too long, you can hide forever!
## Recap
You just built a smart Seeker for hide-and-seek. You used a Perception Trigger to act like eyes. You used a Timer to make those eyes blink. This gives players a fair chance to hide. You also learned about the Scene Graph. It helps keep your game organized. Great job, coder!
## References
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-perception-trigger-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-perception-trigger-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/squid-game-giftbox-device-for-hiding-and-teleportation-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/fortnite-glossary
* https://dev.epicgames.com/documentation/en-us/fortnite/squid-game-minigame-mastery-template-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Hide and Seek 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.