The Magic Doorbell: Starting Your Game with Triggers
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.
The Magic Doorbell: Starting Your Game with Triggers
Have you ever pressed a doorbell? Ding-dong! The sound tells someone inside that you are there. In Fortnite Creative, a Trigger works just like a magic doorbell. It tells your game devices to start doing cool stuff.
You will build a simple game. The game starts when a player walks through a door. You will use Verse to make this happen. It is like programming a robot butler. The butler waits for a guest. Then, the butler opens the door.
What You'll Learn
- What a Trigger is in game design.
- How to use Verse to listen for a signal.
- How to make your game start automatically.
- The basics of connecting devices with code.
How It Works
Imagine a video game level is a house. The player is a visitor. The Trigger is a sensor on the floor. It is invisible. You cannot see it. But it can feel footsteps.
When a player steps on the trigger, it sends a signal. This signal is like a text message. The message says, "Someone is here!"
Other devices in your game listen for this message. For example, a Spawner might hear the message. Then, it creates monsters. A Score Manager might hear it too. Then, it starts counting points.
In Verse, we write code to connect the trigger to these devices. We call this binding an event. It is like tying a string between the doorbell and the chime. When the bell rings, the chime sounds.
We will build a "Start Game" trigger. When a player steps on it, the game begins. We will use a simple Verse script. It will listen for the player. Then, it will tell the game to start.
Let's Build It
First, place a Trigger device in your world. Put it near the start of your island. Make sure it is not in the way.
Next, we need a script. This script will live inside the trigger. It will watch for players. Here is the code. Copy it into your Verse editor.
# This is a simple script for a Trigger device.
# It starts the game when a player steps on it.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is the main script block.
# Think of it as the brain of the trigger.
trigger_manager := class(creative_device) {
# Bind a trigger_device from the editor so we can
# listen to its TriggeredEvent.
@editable
MyTrigger : trigger_device = trigger_device{}
# This line listens for a player.
# "OnBegin" is the event.
# It happens when the game starts.
OnBegin<override>()<suspends> : void =
# Subscribe to the trigger's TriggeredEvent.
# "TriggeredEvent" fires whenever a player
# walks into the trigger volume.
MyTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)
# This function runs when someone walks in.
# "Agent" is the Verse type for the entity
# that activated the trigger.
OnPlayerEntered(Agent : agent) : void =
# Cast the agent to a fort_character so we can
# call character-level functions on them.
if (Character := Agent.GetFortCharacter[]):
# Print a message to the output log.
# Note: in-world HUD text requires a
# hud_message_device placed in the editor;
# Print() is the closest real logging call.
Print("Adventure Begins!")
}```
Let's look at the code. The first lines use `using`. This brings in the Fortnite devices. It is like opening a toolbox.
Next, we define `trigger_manager`. This is a **class** that extends `creative_device`. A script is a set of instructions. It tells the device what to do.
Inside the script, we have `OnBeginPlay`. This is an **event**. An event is something that happens. It happens when the level loads.
Then, we have `OnPlayerEntered`. This is also an event. It happens when a player walks into the trigger. The word `Agent` is a **variable**. A variable holds data. Here, it holds the player who stepped on the trigger.
Finally, we call `Print()`. This is a **function**. A function is an action. It logs a message we can read. We cast the `Agent` to a `fort_character` first, so we can work with the player safely.
## Try It Yourself
Now it is your turn to play. Try to change the message. Instead of "Adventure Begins!", make it say "Quest Begins!"
**Hint:** Look at the last line of the code. Change the words inside the quotes. Save your script. Play your island. Step on the trigger. Did the message change?
## Recap
Triggers are invisible sensors. They detect when players move. They send signals to other devices. Verse helps us connect these signals. You can make games start, spawn items, or change scores. Keep experimenting!
## References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/dungeon-crawler-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/dungeon-crawler-gameplay-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/party-game-4-reusable-game-manager-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/escape-room-key-gameplay-examples-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/escape-room-key-mechanics-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Using the trigger device to start things in your game 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.