Make Your NPCs Talk Back: The Verse AI Voiceline Manager
Make Your NPCs Talk Back: The Verse AI Voiceline Manager
So, you’ve built a fortress. You’ve placed guards. But right now, your NPCs are about as chatty as a loot box—completely silent. It’s creepy. It’s boring. And frankly, it ruins the immersion.
In this tutorial, we’re going to fix that. We’re going to build a Verse Device that acts as the brain for your island’s audio. Instead of manually placing an Audio Player device next to every single guard (which is like trying to mic up a stadium with a single handheld microphone), we’ll create a reusable tool. This tool will let any NPC in your game bark, shout, or sing at the drop of a hat.
By the end of this, your guards won’t just shoot at you; they’ll yell, "Hey! You there!" before they do. Let’s get to work.
What You'll Learn
- Classes in Verse: Think of this as creating a new type of Device.
- Editable Properties: How to let other creators (or you, later) tweak settings without touching code.
- The Scene Graph: Understanding how devices connect to characters in the 3D world.
- Audio Barks: Using the
Audio Playerdevice to trigger sound effects.
How It Works
In Fortnite Creative, you’re used to dragging and dropping devices from the menu. An Audio Player is a device that holds a sound file and plays it when triggered. A Guard Spawner is a device that spawns enemies.
Normally, if you want a guard to yell "Intruder!", you’d have to:
- Place an Audio Player.
- Drag a sound file into it.
- Connect a Trigger to it.
- Repeat this for every single guard.
That’s tedious. That’s the "hard way."
The Verse Way:
We are going to write a script that creates a new kind of device. Let’s call it the AI_Voiceline_Manager.
When you place this device in your level, it will contain everything needed to play a sound:
- The Speaker: An internal
Audio Playerdevice. - The Volume Knob: A setting for how loud the sound is.
- The Delay: A setting for how long to wait before speaking (so they don’t interrupt each other).
Because this is a Class (a blueprint), you can place one AI_Voiceline_Manager on Guard A, and another on Guard B. They are identical twins, but they live in different spots in the Scene Graph (the family tree of your level). When you tell Guard A’s manager to speak, only Guard A’s speaker plays. Guard B stays quiet.
The "Scene Graph" Connection
Imagine the Scene Graph is like the hierarchy of a squad.
- The Level is the Squad Leader.
- The Guard is a Squad Member.
- The AI_Voiceline_Manager is the radio attached to that Squad Member.
If you pull the radio off the Squad Member and put it on the ground, the sound comes from the ground, not the Guard. In Verse, we need to make sure our Manager knows who it belongs to, so the sound projects from the right place.
Let's Build It
We are going to create a Verse script that defines our custom device. This script will expose three settings you can change in the editor: the sound file, whether it can repeat, and a delay.
Step 1: The Setup
- Open Unreal Editor for Fortnite (UEFN).
- Create a new Verse Script. Name it
Ai_Voiceline_Manager. - Copy the code below.
# Import the tools we need
using { /Fortnite.com/Devices } # Gives us access to Audio Players, Triggers, etc.
using { /Fortnite.com/AI } # Gives us access to NPC-specific logic
using { /Verse.org/Simulation } # The core engine logic
# This is our Custom Device Blueprint
# We call it 'concrete' because it's a real device you can place in the world
ai_voiceline_manager := class<concrete>:
# --- EDITABLE PROPERTIES ---
# These are the "knobs" you see in the device panel in UEFN.
# 1. The Sound File
# We link this to an Audio Player device.
# When you place this device in UEFN, you'll drag a sound file into this slot.
@editable
Sound:audio_player_device := audio_player_device{}
# 2. Should it repeat?
# If true, the guard can say the same line twice in a row.
# If false, it waits a cooldown before repeating.
@editable
CanRepeat:logic = true
# 3. The Delay
# Time in seconds before the bark plays.
# 0.0 means instantly. 1.5 means wait 1.5 seconds.
@editable
Delay:float = 0.0
# 4. The Trigger (Optional but recommended)
# This is the "switch" that tells the manager to speak.
@editable
Trigger:trigger_device := trigger_device{}
# --- THE BRAIN ---
# This function runs when the Trigger is activated.
OnTriggered()<suspends>:void=
# If we are waiting, stop waiting
# (Simplified logic for this tutorial: we just play it)
# Play the sound!
# .Play() is the command that says "Make noise."
Sound.Play()
# Optional: Log a message to the console for debugging
# (This shows up in the debugger, not in-game)
Print("Guard said something!")```
### Step 2: Understanding the Code
Let’s break down the "programming speak" using Fortnite terms.
1. `class<concrete>`:
* **Programming Term:** Class.
* **Game Analogy:** This is like creating a new **Blueprint Item** in Creative. You aren’t placing a tree; you’re creating the *definition* of a tree so you can place as many as you want. `concrete` means this device can actually be dragged into the level.
2. `@editable`:
* **Programming Term:** Public Property / Attribute.
* **Game Analogy:** These are the **settings sliders** in the device panel. Without this tag, the variable would be hidden inside the code, like a secret stat you can’t change. With `@editable`, you see it in the UI.
3. `audio_player_device`:
* **Programming Term:** Type.
* **Game Analogy:** This tells Verse, "This variable isn't a number or a word; it’s a specific device that plays audio." It’s like saying "This slot is for a Weapon," not "This slot is for a Key."
4. `OnTriggered`:
* **Programming Term:** Event Handler / Function.
* **Game Analogy:** This is the **Trigger’s logic**. In Creative, you link a Trigger to an Action. In Verse, `OnTriggered` is the function that runs *automatically* when that link is pulled. It’s the "Do This" part of the chain.
5. `Sound.Play()`:
* **Programming Term:** Method Call.
* **Game Analogy:** Pressing the **Play Button** on the Audio Player device.
### Step 3: Using It in Your Island
Now that the script is written, let’s use it.
1. **Compile the Script:** Click the "Compile" button in the Verse editor. If there are no red errors, you’re good.
2. **Place the Device:** Go to the **Verse Devices** tab in the device menu. You should see `AI_Voiceline_Manager`. Drag one onto your map.
3. **Assign a Sound:** Click the device. In the details panel on the right, look for the `Sound` slot. Drag an imported audio file (a bark, a shout, a music cue) from your Project Folder into that slot.
4. **Connect the Trigger:** Drag a `Trigger` device from the menu and place it near your NPC. Link the Trigger to the `AI_Voiceline_Manager`'s `Trigger` input (or just press the button on the manager if you want to test it manually).
5. **Test:** Press Play. When the trigger is activated, your NPC should now "speak" the sound you assigned.
## Try It Yourself
You’ve got the basics working. Now, let’s make it smarter.
**The Challenge:**
Right now, if you spam the trigger, the guard will scream the same line 50 times in a row. It’s annoying.
Modify the `OnTriggered` function to add a **Cooldown**.
* Add a new editable property called `CooldownTime:float = 2.0`.
* Inside `OnTriggered`, check if enough time has passed since the last time it played.
* *Hint:* You’ll need to store the "last played time" in a variable. In Verse, you can use `CurrentTime()` to get the current game time in seconds.
**Hint:**
Think of it like a **respawn timer**. You can’t respawn until the timer hits zero. Here, the "respawn" is the ability to speak again.
```verse
# Example snippet for the hint
LastPlayedTime:float = 0.0
OnTriggered := func():
CurrentTime := CurrentTime()
if (CurrentTime - LastPlayedTime) > CooldownTime:
Sound.Play()
LastPlayedTime = CurrentTime
Recap
We built a custom Verse device that wraps an Audio Player into a reusable package. We learned that:
- Classes are blueprints for devices.
- Editable properties let you customize devices in the editor without touching code.
- Events like
OnTriggeredlet your code react to player actions.
Your NPCs are no longer silent. They’re loud, they’re annoying, and they’re exactly what your island needed. Now go make them yell something funny.
References
- https://dev.epicgames.com/community/snippets/XPJQ/fortnite-ai-voiceline-manager
- https://dev.epicgames.com/community/snippets/VgD8/fortnite-ai-music-manager
- https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/ai/fort_guard_actions
- https://dev.epicgames.com/documentation/en-us/fortnite/stronghold-05-set-up-audio-and-visual-effects-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/ai/fort_npc_actions
Verse source files
- 01-standalone.verse · standalone
- 02-fragment.verse · fragment
Turn this into a guided course
Add fortnite-ai-voiceline-manager 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.