The Loot Goblin’s Playlist: Loading Samples in Verse
The Loot Goblin's Playlist: Loading Samples in Verse
So, you've got a trap that plays a sound when someone steps on it. Cool. But what if that sound is a 30-second orchestral swell of doom, or a custom voice line you recorded in your bathroom? You can't just drag a WAV file into a device and hope for the best. You need to Load a Sample.
Think of this like the Battle Bus: it doesn't carry every song in the world into the lobby. It picks a few specific tracks, loads them up, and plays them when the beat drops. In Verse, we do the same thing. We take a heavy audio file, load it into memory (RAM) once, and then trigger it instantly whenever a player triggers a trap, picks up loot, or gets eliminated. No lag, no loading screens, just pure audio chaos.
What You'll Learn
- The Concept: What "Loading a Sample" actually means in game dev (and why it's not just "playing a sound").
- The Gear: How to use the
Audiocomponent and theLoadfunction. - The Build: Create a "Revenge Trap" that plays a custom sound file when you step on it.
- The Scene Graph: Where that audio file lives in your project hierarchy.
How It Works
In Fortnite Creative, you're used to seeing an "Audio" device in the device list. You click it, pick a sound, and boom—sound happens. But that device is a black box. It handles the loading, the playing, and the stopping for you.
In Verse, we want more control. We want to say, "Hey, when Player A touches this button, play this specific file, but only if they have less than 50 HP." To do that, we need to understand two things: Assets and Components.
1. The Asset (The Loot)
An Asset is any file you import into your project—textures, meshes, sounds. Think of an Asset like a Loot Box in the game. It sits on the ground, waiting to be picked up. An audio file (like a .wav or .mp3) is just a Loot Box that contains sound waves instead of gold bars.
2. The Component (The Backpack)
A Component is a piece of functionality attached to an object. Think of it like a Backpack or a Utility Item. A chair doesn't naturally have sound capabilities. But if you attach an "Audio Component" to it, it becomes a speaker. In Verse, we attach an Audio component to an entity (like a button or a trap) to give it the ability to play sounds.
3. Loading (The Bus Ride)
You don't want to load a 50MB song every single time someone steps on a trap. That's like calling the Battle Bus for every single player individually—it's inefficient and slow. Instead, we Load the sample once when the game starts (or when the map initializes). This is like the Bus picking up the playlist before the match even begins. The sound is now in the game's memory (RAM), ready to be played instantly.
4. Playing (The Drop)
When the trigger event happens (e.g., OnBeginOverlap), we tell the loaded sample to Play. This is the moment the player drops from the bus. It's instant, sharp, and loud.
Let's Build It
We are going to build a "Scream Trap." When a player steps on a pressure plate, it plays a custom scream sound.
Step 1: Get Your Audio File
You need a sound file. Any sound file. Go to your computer, find a .wav or .mp3 file (maybe a scream, a laugh, or a bass drop), and save it somewhere easy to find.
Step 2: Import into UEFN
- Open your Island in UEFN.
- Open the Content Browser (the folder icon on the left).
- Drag your audio file from your computer folder directly into the Content Browser.
- You should see a new icon appear. Name it something simple, like
ScreamSample.
Step 3: The Verse Code
Create a new Verse script. We're going to wire a trigger_device to play our imported sound through an audio_player_device when a player steps on it.
Here is the code. Don't panic—it's shorter than a loot drop description.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Concurrency }
# This is our main script. It inherits from creative_device,
# which means it can sit in the world as a placed device.
scream_trap_device := class(creative_device):
# This is our 'Backpack' (Component) that will hold the audio.
# audio_player_device is a real UEFN device you place on your island
# and wire up in the editor. It wraps your imported sound asset.
# Drag an Audio Player Device from the device list onto your island,
# then assign it to this slot in the Verse Device details panel.
@editable
AudioPlayer : audio_player_device = audio_player_device{}
# This is our trigger — the pressure plate the player walks over.
# Place a Trigger Device on your island and assign it here.
@editable
Trap : trigger_device = trigger_device{}
# This function runs ONCE when the island starts.
# Think of this as the 'Pre-Match Lobby' phase.
OnBegin<override>()<suspends> : void =
# Subscribe to the trigger's TriggeredEvent.
# Whenever a player steps on the Trap, TriggerSound is called.
# This is like the Bus picking up the playlist before the drop.
Trap.TriggeredEvent.Subscribe(OnTrapped)
# This function runs when a player steps on the trigger.
# The agent parameter is the player who activated the trap.
OnTrapped(Agent : ?agent) : void =
# Tell the AudioPlayer device to play its assigned sound asset.
# The sound asset itself is configured on the audio_player_device
# in the UEFN editor — set it to your imported ScreamSample there.
# This is the 'Drop'. Instant playback.
AudioPlayer.Play()
# To make this work in UEFN, you:
# 1. Place a 'Verse Device' on your island and assign this class to it.
# 2. Place an 'Audio Player Device' and assign your ScreamSample asset to it
# via that device's Sound property in the Details panel.
# 3. Place a 'Trigger Device' where you want the pressure plate.
# 4. In the Verse Device Details panel, drag the Audio Player Device into
# 'AudioPlayer' and the Trigger Device into 'Trap'.
# No manual editor wiring needed — the Subscribe call handles the connection.```
### Walkthrough of the Code
1. `class(creative_device)`: This defines our script as a **creative_device**. It means it can be placed in the world, just like a Trap or a Button. `creative_device` is the real base class for all placeable Verse devices in UEFN.
2. `AudioPlayer : audio_player_device`: We reference an **Audio Player Device** already placed on the island. This device wraps your imported sound asset and is the real mechanism UEFN exposes for custom audio playback. It's empty until you assign your `ScreamSample` to it in the editor.
3. `OnBegin<override>()<suspends> : void`: This is the **Initialization** phase. It runs exactly once when the game begins. We use this to **Subscribe** to the trap's trigger event. Subscribing here means "register a listener so we're ready to react." If we called `Play` here, the sound would play once when the game starts and then never again.
4. `OnTrapped(Agent : agent) : void`: This is the **Event Handler**. It fires every time a player steps on the `Trap`. When it runs, it tells the `AudioPlayer` to **Play** the loaded sample.
## Try It Yourself
**Challenge:** Modify the `scream_trap_device` to play the sound **twice** in quick succession when triggered.
**Hint:** Look at the `OnTrapped()` function. You can call `AudioPlayer.Play()` more than once. Try adding a small delay between them if you want it to sound like an echo. (Note: Verse has a `Sleep()` function you can use for delays — wrap the second call with `Sleep(0.5)` inside a `spawn` block so it doesn't block the main flow).
**Bonus Challenge:** Can you find a way to stop the sound if the player moves away? (Hint: Look for a `Stop()` function on the `AudioPlayer` device, and subscribe to an exit event on your trigger.)
## Recap
* **Assets** are your files (sounds, textures, etc.). They're your loot. Configure them on the `audio_player_device` in the UEFN editor.
* **Devices** are the tools placed in the world. An `audio_player_device` lets your island make noise on demand.
* **Subscribing** happens once at the start. It registers your listener so the trap is armed.
* **Playing** happens on demand. It triggers the sound instantly when the event fires.
Now go make your island scream. Or laugh. Or play dubstep. The bus is waiting.
## References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-patchwork-instrument-player-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/uefn/spatial-profiler-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/spatial-profiler-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/importing-assets-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/38-00-fortnite-ecosystem-updates-and-release-notes
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Loading Samples 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.