Hello, New Friend! Spawning NPCs with Verse
Hello, New Friend! Spawning NPCs with Verse
Have you ever wanted to create a friend in your Fortnite island? Or maybe a tricky enemy to challenge players? In UEFN, these are called NPCs. This tutorial teaches you how to use Verse to detect when an NPC appears. You will build a simple system that shouts "Welcome!" when a new character spawns.
What You'll Learn
- What an NPC Spawner device does.
- How to use a "signal" in Verse.
- How to make a prop change color when an NPC appears.
How It Works
Think of your game island like a busy playground. The NPC Spawner is like a magic box. When you press a button, it creates a new character from thin air.
But how does your code know the character is there? It uses a signal. A signal is like a fire alarm. When the alarm goes off, it means something specific happened. In this case, the signal goes off when the NPC Spawner creates a new character.
We will connect this signal to a Prop Mover. A Prop Mover is a device that can change things. We will tell it to turn a light green when the signal fires. This way, you can see exactly when the NPC arrives.
Let's Build It
First, place an NPC Spawner device in your island. Place a Light or a Prop Mover nearby. We want the light to turn green when the NPC appears.
Here is the Verse code to make it work.
# This is the main script for our island.
# It connects the spawner to our light.
using { /Fortnite.com/Devices }
# This is our "Container" for the script.
# Think of it as a box that holds our rules.
actor Main is:
# This is the NPC Spawner we placed in the level.
# We link it here so we can use it.
my_spawner: NpcSpawnerDevice = NpcSpawnerDevice{}
# This is the light we want to change.
my_light: Light = Light{}
# This is the "signal" we listen to.
# It fires when an NPC is born.
OnNpcSpawned := my_spawner.SpawnedEvent
# This is the main loop.
# It waits for the signal to fire.
on begin() is:
# We wait for the SpawnedEvent signal.
# When it fires, the code inside runs.
for event : OnNpcSpawned do:
# The NPC has spawned!
# Let's turn the light green.
my_light.SetColor(Color{R:0.0, G:1.0, B:0.0})
# Let's wait a moment before turning it off.
Wait(2.0)
# Turn the light back to white.
my_light.SetColor(Color{R:1.0, G:1.0, B:1.0})
Walkthrough
my_spawner: NpcSpawnerDevice: This line tells Verse, "Hey, I have a special box calledmy_spawner." You must drag your NPC Spawner device into this slot in the UEFN editor.SpawnedEvent: This is the signal. It is like a button that only presses itself when a new NPC appears.for event : OnNpcSpawned do:: This is a loop. It sits still and waits. When the signal fires, it jumps into the code block.SetColor: This function changes the light. We set it to green (G:1.0) to show success.
Try It Yourself
Now it is your turn to customize!
Challenge: Instead of turning the light green, make it turn red and play a sound effect when the NPC spawns.
Hint: You can change the color by changing the R value to 1.0 and the G and B values to 0.0. To play a sound, you might need to add a Sound Device to your island and trigger it in the same block.
Recap
You learned how to use the SpawnedEvent signal. This signal tells your code when an NPC appears. You connected this signal to a light to create a visual reaction. This is the first step to making smart NPCs!
References
- 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/using-npc-spawner-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/understanding-npc-behavior-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/metahuman-overview-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/metahuman-overview-in-unreal-editor-for-fortnite
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add Signaled when a character is spawned from the NPC Spawner Device. 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 guide 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.