Stop the Reinforcements: Subscribing to Events in Verse
Stop the Reinforcements: Subscribing to Events in Verse
So, you’ve built a stronghold. You’ve placed your guards. You’ve set up the traps. But there’s one problem: when those guards get wiped out, nothing happens. The game just... waits. Or worse, it crashes because your script didn’t know when to react.
In Fortnite, you know that feeling when the storm circle shrinks and you suddenly have to move? That’s an event. In Verse, we don’t just write code that runs once and stops. We write code that listens. Today, we’re going to teach your island how to react the moment a reinforcement spawns. No more guessing. No more lag. Just pure, reactive chaos.
What You'll Learn
- What an Event is: Think of it as a "Ping" in party chat.
- Subscribing: How to tell Verse, "Hey, tell me when this happens."
- The Handler: Writing the function that actually does the thing (like spawning a trap or playing a sound).
- Reinforcement Spawners: A quick look at how Stronghold devices work under the hood.
How It Works
Imagine you’re holding a controller. You press a button, and a trap goes off. That’s a direct command. But what if you want a trap to go off only when an enemy steps on a specific tile? You can’t just say "go off." You have to say, "Watch the tile. If someone touches it, then go off."
In programming, this is called Event-Driven Programming.
The Concept: The "Subscribe" Pattern
Think of a Variable as a loot box. It sits there, waiting to be opened. Think of an Event as the moment that loot box opens. Think of Subscribing as setting a trap around that loot box.
When you Subscribe to an event, you are telling Verse: "I don't know when this is going to happen, but when it does, run this specific piece of code."
In the context of a Stronghold, a Reinforcement Spawner is a device that creates enemy guards at set intervals. It has a built-in signal called SpawnedEvent. This signal screams, "I just created a guard!" into the void. If you don’t subscribe to it, nobody hears it. If you do subscribe, Verse calls your custom function, and you can make that new guard glow red, drop a banana, or explode immediately.
The Syntax: Subscribe
In Verse, the syntax is pretty straightforward once you see the pattern:
DeviceName.EventName.Subscribe(YourFunctionName)
- DeviceName: The object doing the action (e.g., your spawner).
- EventName: The specific moment you care about (e.g.,
SpawnedEvent). - YourFunctionName: The function you wrote to handle the reaction.
It’s like setting a tripwire. The wire is the event. The explosion is your function. When the wire is tripped, the explosion happens.
Let's Build It
We’re going to build a simple "Reinforcement Alert" system. When a new guard spawns, we’ll print a message to the screen and maybe flash the screen red. This proves our code is listening.
Step 1: The Setup
- Open UEFN.
- Place a Stronghold Guard Spawner device in your map.
- Name it
MyReinforcementSpawnerin the details panel (this is crucial so Verse knows which device to watch). - Create a new Verse script and attach it to a device (like a Script Device or the Spawner itself if supported, though usually, we attach to a generic Script Device and reference the spawner).
Step 2: The Code
Here is the Verse code. Don’t worry if it looks alien; we’ll break it down line by line.
Walkthrough
OnReinforcementSpawned(SpawnedGuard: Actor): This is your Handler. It’s a regular function, but it has a special job. It takes one argument:SpawnedGuard. This is the actual guard actor that just appeared. It’s like the loot box that just opened. You can now do things with it (likeSpawnedGuard.SetColor(Red)).OnBegin: This is the Start Screen. It runs once when the map loads. It’s where you set up your subscriptions. You don’t subscribe inside the handler; you subscribe at the start, so Verse is always listening.MySpawner.SpawnedEvent.Subscribe(OnReinforcementSpawned): This is the magic line. You are attaching your handler function to the spawner’s event. From this point forward, every time a guard spawns, Verse automatically callsOnReinforcementSpawned.
Try It Yourself
Now that you’ve got the basics, try to level up your island.
Challenge: Modify the code above so that when a reinforcement spawns, it immediately turns Red for 2 seconds, then turns back to its normal color.
Hint:
- You’ll need to use
SpawnedGuard.SetColor()inside your handler. - To make it turn back, you might need to use a
Sleep()function (which pauses the code for a few seconds) or create a second event. - Remember:
SetColortakes aColorvalue. You can useColor(1.0, 0.0, 0.0)for red.
Don’t peek at the solution until you’ve tried! (Spoiler: You might need to create a separate function for "turning back" and subscribe to a timer, or just accept the red glow for now.)
Recap
- Events are signals that something happened (like a guard spawning).
- Subscribing is telling Verse to listen for that signal.
- Handlers are the functions that run when the signal is received.
OnBeginis where you set up your subscriptions so they’re active for the whole game.
You’ve just taken your first step into reactive game design. No more static maps. Your island is now alive, watching, and reacting. Next time, we’ll look at how to handle when those guards die. Until then, keep building, keep breaking, and keep coding.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/stronghold-03-add-verse-script-to-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/verse-stronghold-template-3-scripting-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/stronghold-03-add-verse-script-to-devices-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/team-elimination-6-handling-a-player-joining-a-game-in-progress-in-verse
- https://dev.epicgames.com/documentation/en-us/fortnite/stronghold-05-set-up-audio-and-visual-effects-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-fragment.verse · fragment
- 02-fragment.verse · fragment
Turn this into a guided course
Add Subscribing to reinforcement spawned event 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
- Subscribing to reinforcement spawned event ↗
- The Stronghold Game Manager Verse device is used to manage, monitor, and control the AIs at the Stronghold ↗
- stronghold-03-add-verse-script-to-devices-in-unreal-editor-for-fortnite ↗
- team-elimination-6-handling-a-player-joining-a-game-in-progress-in-verse ↗
- Have a separate case for when the reinforcements spawn ↗
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.