How to Build Your First Verse Script (Without Losing Your Mind)
How to Build Your First Verse Script (Without Losing Your Mind)
So you've placed a trigger, hooked it up to a speaker, and it works. Great. But what if you want the speaker to play a different sound based on who triggered it? Or what if you want to track how many people jump off your custom cliff? That's where Verse comes in. Think of Verse as the brain behind the brawn. The devices are the muscles, but Verse is the nervous system deciding what happens when things get touched.
In this tutorial, we're going to create a "Revenge Trap." It's simple: when a player steps on a plate, they get launched into the air, and a counter goes up to track how many times they've been launched. We'll build this using a custom Verse device, which is basically a blank slate that lets you write your own logic instead of just plugging wires together.
What You'll Learn
- The Scene Graph: Understanding how UEFN sees your island as a hierarchy of objects.
- Creating a Script: How to add a new Verse file to your project.
- Editing Properties: Using
@editableto make your script talk to the devices in your level. - The Basics: Writing a tiny bit of code that reacts to a player touching a trigger.
How It Works
Before we write a single line of code, we need to understand the Scene Graph. If you've ever looked at the Outliner in UEFN, you've seen the Scene Graph. It's like a family tree for your island. You have the World, inside that are Actors (props, lights, devices), and inside those are Components (meshes, colliders, scripts).
In Verse, we don't just "write code." We write code that lives on an Actor. This is called a Device.
- The Script: This is the file you write. It's like the rulebook.
- The Device: This is the thing in your level that runs the rulebook.
@editable: This is a magic keyword. It tells Verse, "Hey, I want to connect this piece of code to a device I'll place in the world later." It's like leaving a wire hanging out, waiting for you to plug it into a speaker or a trigger.
We're going to make a script that watches a Trigger Volume (the thing you place to detect players). When a player touches it, we'll use a Prop Mover to launch them up. Simple, effective, and slightly chaotic.
Let's Build It
Step 1: Open the Verse Explorer
- Open your Fortnite Creative project in UEFN.
- In the top menu bar, go to Verse > Verse Explorer.
- In the Verse Explorer window, right-click on your project name (it's usually at the top of the tree).
- Select Add new Verse file to project.
- Name it
RevengeTrap. Click OK.
You now have a blank canvas. It's empty. Let's fill it.
Step 2: The Code
Copy and paste this code into your new RevengeTrap.verse file. Don't worry if it looks like alien hieroglyphics; we'll break it down line by line.
# 1. Import the libraries we need.
# These are like the toolboxes containing all the Fortnite devices.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# 2. Define the Script Class.
# Think of this as the "Blueprint" for our device.
# It inherits from 'creative_device', which means it can interact with the game world.
RevengeTrapScript := class(creative_device):
# 3. The @editable keyword.
# This creates a property in the Device Properties panel in UEFN.
# It allows us to link a Trigger Volume from our level to this script.
@editable
TriggerVolume : trigger_device = trigger_device{}
# It also allows us to link a Prop Mover to launch the player.
@editable
PropMover : prop_mover_device = prop_mover_device{}
# 4. A variable to count launches.
# This is like a scoreboard that lives inside this script.
# 'var' makes it mutable so we can increment it later.
var LaunchCount : int = 0
# 5. The 'OnBegin' function.
# This runs once when the game starts.
OnBegin<override>()<suspends> : void =
# Let's print a message to the console to make sure it's working.
# 'Print' is like shouting into the void to see if anyone hears you.
Print("Revenge Trap Initialized! Get ready to fly.")
# Subscribe to the trigger's TriggeredEvent so OnTriggerEntered
# is called whenever a player walks into the Trigger Volume.
# TriggeredEvent sends ?agent, so our handler must accept ?agent.
TriggerVolume.TriggeredEvent.Subscribe(OnTriggerEntered)
# Keep this coroutine alive for the lifetime of the game.
loop:
Sleep(1.0)
# 6. The 'OnTriggerEntered' function.
# This runs every time something enters the TriggerVolume.
# trigger_device fires TriggeredEvent with an optional agent (?agent).
OnTriggerEntered(MaybeAgent : ?agent) : void =
# Increment our counter (add 1 to LaunchCount).
set LaunchCount += 1
# Print the new count to the console.
Print("Player launched! Total launches: {LaunchCount}")
# Activate the Prop Mover.
# prop_mover_device uses 'Begin' to start moving the prop.
PropMover.Begin()
# Note: trigger_device has a built-in re-trigger delay you can set
# in UEFN's Device Properties panel, which prevents instant re-firing.
# If you need a code-side delay, move this logic into a separate
# async helper spawned with 'spawn{ }' and call Sleep(1.0) there.```
### Step 3: Walkthrough
Let's look at what we just did, using Fortnite mechanics as our guide.
* **`using { ... }`**: These are your **Libraries**. Imagine you're building a trap. You need a blueprint, some wood, and nails. In Verse, these lines import the pre-made code for Devices, Characters, and Simulation. Without these, your script doesn't know what a "trigger" or a "player" is.
* **`RevengeTrapScript := class(creative_device):`**: This defines our **Class**. A class is like a template. If you were building 100 revenge traps, you'd use this one template 100 times. Each instance (each device in your level) will have its own copy of the variables. Notice we use `creative_device` — that is the real base type for all custom Verse devices in UEFN.
* **`@editable`**: This is the most important part for beginners. When you see `@editable`, think of it as a **port**. In UEFN, when you place this device, you'll see these properties in the "Device Properties" panel on the right. You can drag and drop a Trigger Volume from your level into that `TriggerVolume` slot. This connects the physical object in the world to the code.
* **`OnBegin`**: This is the **Loadout Screen**. It runs once when the match starts. We used it to print a message to the console and to subscribe to the trigger's event. The console is like the chat log for developers. You can see it in UEFN by opening the "Output Log" or in-game by pressing `~` (tilde) if you have cheats enabled.
* **`TriggerVolume.TriggeredEvent.Subscribe(OnTriggerEntered)`**: This is how Verse connects events to functions. Instead of overriding a built-in method, we tell the `trigger_device` to call our function whenever it fires. Think of it like signing up for a notification.
* **`OnTriggerEntered(Agent : agent)`**: This is the **Elimination Event**. It fires whenever a player (or NPC) enters the trigger volume. The `trigger_device` passes an `agent` — the game's general term for any player or character — so we don't need an extra type-check for basic launching.
* **`PropMover.Activate(Agent)`**: This is the **Action**. We tell the Prop Mover to move. Since we set up the Prop Mover in UEFN to move up, the player goes up.
### Step 4: Connecting It in UEFN
Code is useless if it's not connected.
1. In UEFN, go to your **Device Palette**.
2. Search for `RevengeTrap`. You should see your custom device there.
3. Place it in your level.
4. Place a **Trigger Volume** nearby. Set its size to be a small platform.
5. Place a **Prop Mover** above the trigger. Set it to move up (e.g., 500 units) and set it to **Loop** or **Once** depending on your preference.
6. Click on your `RevengeTrap` device.
7. In the **Device Properties** panel on the right, you'll see two slots: `TriggerVolume` and `PropMover`.
8. Drag the Trigger Volume from your level into the `TriggerVolume` slot.
9. Drag the Prop Mover into the `PropMover` slot.
### Step 5: Test It
1. Press **Play** in UEFN.
2. Walk onto the platform.
3. You should get launched into the air.
4. Open the console (if possible) or check the Output Log in UEFN to see the "Player launched!" message.
## Try It Yourself
You've got a basic trap working. Now, make it better.
**Challenge:** Modify the script so that the Prop Mover moves *higher* every time a player is launched. (Hint: You'll need to change the `Target` property of the Prop Mover dynamically in the code. Look up how to set a float value on a device in the Verse documentation).
**Hint:** You can't just change the `PropMover`'s visual target easily in Verse without knowing its internal structure. Instead, try this: Add a variable `LaunchHeight` to your script. Start it at 500. Every time `OnTriggerEntered` runs, add 100 to `LaunchHeight`. Then, you'll need to figure out how to apply that height to the Prop Mover. If you get stuck, remember: the Prop Mover has a `Target` property that can be a vector.
## Recap
* **Verse scripts** are the logic behind your devices.
* **`@editable`** lets you connect code to physical devices in your level.
* **Classes** are templates for your devices.
* **Functions** like `OnBegin` and `OnTriggerEntered` are the events that drive your game.
You've just written your first Verse script. It's not just a trigger; it's a *smart* trigger. Now go make something chaotic.
## References
* https://dev.epicgames.com/documentation/en-us/fortnite/using-analytics-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/uefn/using-analytics-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/uefn/verse-parkour-template-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/create-your-own-device-in-verse
* https://dev.epicgames.com/documentation/fortnite/verse-parkour-template-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Creating the Verse Script 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.