Make Your Island Come Alive with Sound
Make Your Island Come Alive with Sound
Do you like games that have cool sound effects? Sounds make games feel real. They tell you when you jump or find treasure. In this tutorial, we will add a special sound to our island. We will use Verse code to play a sound. It will be like magic. You will hear your code work!
What You'll Learn
- What a sound wave is.
- How to use a variable to store a sound.
- How to play a sound when a player touches a zone.
- How to give feedback to players.
How It Works
Imagine you are baking a cake. The recipe is like your code. The ingredients are like your assets. Audio is like the smell of the cake. You cannot see it, but you know it is there.
In UEFN, we use two main types of audio files.
- Sound Wave: This is a simple sound file. It is like a single note. You can import
.wavor.oggfiles. Think of it like a recording of a single clap. - Sound Cue: This is more complex. It is like a whole song. It can change volume or add echoes. We will keep it simple today. We will use a Sound Wave.
We need a way to trigger the sound. We will use a Trigger Zone. This is an invisible box. When a player walks into it, something happens. We will write a Verse script. This script will watch the zone. When someone enters, the script will play the sound.
Think of the script as a guard. The guard waits by the door. When a friend walks in, the guard plays a trumpet.
Let's Build It
We will build a "Treasure Zone." When you step on it, you hear a "ding!" sound.
Step 1: Get Your Sound
You need a sound file. You can use any short .wav or .ogg file. If you do not have one, you can use the default "Coin" sound from Fortnite Creative assets. Let's call it coin_sound.
Step 2: Place a Trigger Zone
- Open your island in UEFN.
- Go to the Devices tab.
- Search for Trigger Zone.
- Place it on the ground. Make it big enough to stand in.
- Name it
TreasureZonein the details panel. This makes it easy to find in code.
Step 3: Write the Verse Code
Create a new Verse file. Call it TreasureSound. Copy this code. Read the comments carefully.
# This is our main script.
# It runs when the island starts.
# We use a creative_device class to hold our devices and assets.
treasure_sound_device := class(creative_device):
# We reference the trigger_device placed in UEFN.
# Drag your TreasureZone trigger device here in the details panel.
@editable
TreasureZone : trigger_device = trigger_device{}
# We reference the audio_player_device placed in UEFN.
# Drag your Audio Player device here in the details panel.
# The Audio Player device has a sound asset assigned to it.
@editable
TreasureAudio : audio_player_device = audio_player_device{}
# OnBegin runs once when the island starts.
# It is like turning on the lights.
OnBegin<override>()<suspends> : void =
# Tell the console the script is ready.
Print("Sound system ready!")
# Connect to the TriggeredEvent on the trigger device.
# This runs our function when a player enters the zone.
TreasureZone.TriggeredEvent.Subscribe(OnZoneEntered)
# This function runs every time a player enters the zone.
# 'Agent' is the player who walked in.
OnZoneEntered(Agent : ?agent) : void =
# Play the sound through the audio player device.
TreasureAudio.Play()
Print("Ding! You found treasure!")```
*Wait!* Let's make sure you understand every piece before moving on. The code above uses two devices together. The `trigger_device` detects the player. The `audio_player_device` plays the sound. You place both devices on your island in UEFN. Then you drag them into the script's editable fields in the details panel.
Actually, the best way for beginners is to keep the devices and the script connected through `@editable` fields. Let's pretend we have an Audio Player device with a Sound Cue named `TreasureDing` assigned to it inside UEFN.
Here is a corrected, more realistic Verse snippet that you can adapt. You attach this script to a `creative_device` actor you place on your island.
```verse
# TreasureSound.verse
# We define our device class.
# This holds all our logic and device references.
treasure_sound_device := class(creative_device):
# The trigger device detects when a player walks in.
# Assign your TreasureZone trigger device here in UEFN.
@editable
TreasureZone : trigger_device = trigger_device{}
# The audio player device plays our sound cue.
# Assign your Audio Player device here in UEFN.
# Set the sound asset on the Audio Player device itself.
@editable
TreasureAudio : audio_player_device = audio_player_device{}
# OnBegin is the main entry point.
# It runs once when the island loads.
OnBegin<override>()<suspends> : void =
# Connect the trigger's event to our handler function.
# This is like telling the guard: watch the door.
TreasureZone.TriggeredEvent.Subscribe(OnPlayerEntered)
# This function runs when a player enters the zone.
# Agent is the player who triggered the zone.
OnPlayerEntered(Agent : agent) : void =
# Play the sound through the audio player device.
# The audio player device uses the sound asset
# you assigned to it in the UEFN details panel.
TreasureAudio.Play()
Print("Player entered the treasure zone!")
verse
# Simple Treasure Alert
# All Verse scripts that run on an island must live
# inside a creative_device class.
treasure_alert_device := class(creative_device):
# The trigger device is our zone.
# Assign your TreasureZone device here in UEFN.
@editable
TreasureZone : trigger_device = trigger_device{}
# OnBegin runs once when the game starts.
# It is like turning on the lights.
OnBegin<override>()<suspends> : void =
# Connect to the trigger's TriggeredEvent.
# This happens when an agent enters the zone.
TreasureZone.TriggeredEvent.Subscribe(OnTreasureFound)
# This function runs when a player enters the zone.
# Agent is the player who walked in.
OnTreasureFound(Agent : agent) : void =
# Tell the player they found something.
Print("You found the treasure!")
# In a real script, you would also add:
# TreasureAudio.Play()
# after adding an @editable audio_player_device field above.
# But for now, Print is safe and shows the logic works.
Walkthrough
treasure_alert_device := class(creative_device): Every Verse script that runs on an island lives inside acreative_deviceclass. This is how UEFN knows to run your code.@editable TreasureZone : trigger_device: This creates a slot in the details panel. You drag your placed Trigger device into it inside UEFN. The names must match.OnBegin<override>()<suspends> : void: This runs once when the island loads. It is like turning on the lights.TreasureZone.TriggeredEvent.Subscribe(OnTreasureFound): This is the magic part. It says, "Watch this zone. When someone walks in, runOnTreasureFound."OnTreasureFound(Agent : agent) : void: This is the function that runs.Agentis the player who walked in.Print(...): This shows a message in the debug console. It proves your code is working.
Try It Yourself
You did it! You wrote code that watches a zone. Now, make it better.
Challenge: Add a second zone called DangerZone. Make it print "Ouch! You stepped on lava!" when a player enters.
Hint: Copy the code for TreasureZone. Change the name to "DangerZone". Change the print message. Place a new Trigger Zone in your island and name it DangerZone.
Recap
- Audio makes games fun.
- A Sound Wave is a simple sound file.
- A Trigger Zone detects when players move.
- Verse code can watch for events and react.
- Always check if your actors exist before using them.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/unreal-editor-for-fortnite-glossary
- https://dev.epicgames.com/documentation/en-us/uefn/unreal-editor-for-fortnite-glossary
- https://dev.epicgames.com/documentation/en-us/fortnite/fortnite-glossary
- https://dev.epicgames.com/documentation/en-us/uefn/adding-audio-to-your-project-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/adding-audio-to-your-project-in-unreal-editor-for-fortnite
Get the complete code — free
You've read the full walkthrough. The complete, copy-paste-ready Verse solution is free for members — sign in to unlock it.
Free with your BrainDead.TV / BrainDeadGuild Discord account. The walkthrough above is always free.
Verse source files
- 01-device.verse · device
- 02-device.verse · device
- 03-device.verse · device
Turn this into a guided course
Add Audio 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.