Build Your First Custom Verse Device
Build Your First Custom Verse Device
Imagine you have a magic box. You can tell it exactly what to do. It can count points. It can change colors. It can make things appear. In Fortnite Creative, these boxes are called Devices. They are like Lego bricks for game logic.
But what if you want a box that doesn't exist yet? You can build one! This is called a Verse Device. It is a special device that runs your own code. You write the rules. The device follows them. Let's make a simple "Hello World" device. It will say "Hello" when you touch it.
What You'll Learn
- What a Verse Device is.
- How to add a Verse Device to your island.
- How to write code that reacts to a player.
- How to test your code in the editor.
How It Works
Think of a Verse Device like a robot. The robot sits in your game world. It has sensors. It has a brain. The brain is your code.
In Fortnite, we use a Scene Graph. This is just a fancy name for a family tree of objects. Every prop, every device, and every player is part of this tree. Your Verse Device is one branch of this tree.
When you create a Verse Device, you are giving it a new job. You write a script. The script listens for events. An Event is something that happens. Like a player walking into a zone. Or a timer finishing. When the event happens, your code runs.
You don't need to know complex math. You just need to know what you want the device to do. Do you want it to shout? Do you want it to change color? You tell the device in Verse.
Let's Build It
We will make a device that prints a message when a player touches it. This is the simplest way to see Verse in action.
Step 1: Add the Device
- Open your island in UEFN.
- Go to the Devices menu.
- Search for Verse.
- Drag the Verse device into your world. Place it on the ground.
Step 2: Write the Code
Click on the Verse device you just placed. You will see a code window open. This is your Script. A script is a set of instructions.
Clear any code that is there. Copy and paste this code instead:
# This is a simple Verse script for a device.
# It says hello when a player enters its zone.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is the main class for our device.
# Think of it as the robot's body.
my_hello_device := class(creative_device):
# A trigger_device is wired in the editor to detect when
# a player walks into its zone.
# note: wire this to a Trigger Device placed near your Verse device in UEFN.
@editable
Trigger : trigger_device = trigger_device{}
# This runs once when the game starts.
OnBegin<override>()<suspends>: void=
# We print a message to the log.
# This helps us know the code is running.
Print("My device is ready!")
# Subscribe to the trigger so we know when a player enters.
Trigger.TriggeredEvent.Subscribe(OnTriggered)
# This runs when a player enters the trigger zone.
# 'Agent' is the player who touched it.
OnTriggered(Agent : ?agent): void=
# Check if the agent is a player.
if (A := Agent?):
# Print a friendly message.
Print("Hello, Player!")```
### Step 3: Understand the Code
Let's look at the important parts.
* `my_hello_device := class(creative_device)`: This names your device. You can name it anything. It is like naming your robot.
* `class(creative_device)`: This tells Verse this is a device. It inherits powers from the base device.
* `OnBegin`: This is an **Event**. It runs when the game starts. It is like turning on the robot.
* `@editable Trigger : trigger_device`: This is a real Fortnite **Trigger Device** wired in the editor. It detects when a player walks into its zone and fires `TriggeredEvent`.
* `Trigger.TriggeredEvent.Subscribe(OnTriggered)`: This tells the device to call `OnTriggered` every time a player touches the trigger. This is how Verse listens for overlap events.
* `Print`: This is a **Function**. A function is a command. `Print` sends text to the output log. It is like the robot talking to you.
### Step 4: Test It
1. Click **Save** in the code window.
2. Click **Play** in the editor.
3. Walk into the Verse device.
4. Look at the **Output Log** (usually at the bottom of the screen).
5. You should see "My device is ready!" and "Hello, Player!".
6. The device should turn green.
You just made a custom device! It didn't exist before. You built it from scratch.
## Try It Yourself
Now that you have a working device, try this challenge.
**Challenge:** Change the code so that it prints the player's name instead of "Hello, Player!".
**Hint:** Look at the `player` variable. It is of type `player`. You can use the `GetDisplayName()` function to get the name. Try this line: `Print(Player.GetDisplayName())`.
**Hint 2:** Make sure you check if `Player` is valid before using it. Your `if` statement should look like this:
```verse
# note: GetDisplayName() lives in /Fortnite.com/Players and returns a string.
OnTriggered(Agent : agent): void=
if (Player := player[Agent]):
Print(Player.GetDisplayName())
Recap
- Verse Devices let you build custom game logic.
- You add a Verse Device from the Devices menu.
- You write code to handle events like touching or starting.
- Use
Printto debug and see what is happening. - Always test your code by playing your island.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-npc-spawner-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/using-npc-spawner-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/getting-started-with-devices-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/using-lego-assembly-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/disappearing-platform-on-loop-using-verse-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
- 02-fragment.verse · fragment
Turn this into a guided course
Add create-your-own-device-in-verse 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
- Visit [here](../uefn/create-your-own-device-in-verse.md) to create a verse device. ↗
- Visit [here](create-your-own-device-in-verse.md) to create a verse device. ↗
- Make Your Own Device with Verse ↗
- See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device. ↗
- See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device. ↗
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.