Don't Shoot the Teddy Bear: Adding Targets to Your Verse Island
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
Don't Shoot the Teddy Bear: Adding Targets to Your Verse Island
So, you’ve got a shooting gallery. It’s cool. But right now, it’s too easy. You’re just clicking away at moving targets like a casual player who hasn’t seen a sniper rifle since Chapter 1. Boring.
To make your island actually test a player’s skills (and rage), you need targets. Not just any targets, but smart targets. Some give points, some take them away. In Fortnite Creative, we call these "targets" because they’re what you’re shooting at. In Verse, we’re going to teach them how to behave like good citizens (or bad ones) using code.
Today, we’re building a classic "Good vs. Bad" target system. You’ll learn how to tell the game: "If they hit this, add points. If they hit this, subtract points." It’s the difference between a loot drop and a storm circle closing in.
What You'll Learn
- The Scene Graph: How devices talk to each other (like a squad leader coordinating a push).
- Variables: Storing scores and target states (like keeping track of your HP).
- Events: Reacting when a player clicks a trigger (like a trap activating).
- Wrappers: Bundling code and data together so you don’t have to write the same logic twice (like cloning a blueprint).
How It Works
In Fortnite Creative, you might drag a "Target Dummy" into the world and hope for the best. In Verse, we need to be more specific. We need to define what the target is, what happens when it’s hit, and who keeps score.
Think of it like this:
- The Target (Entity): This is the object in the world. It has properties (is it a teddy bear? is it a bomb?).
- The Event (Trigger): Something needs to happen to the target. Usually, a bullet hits it. In Verse, we "subscribe" to this event. It’s like setting a trap; you don’t know when it will trigger, but you know what to do when it does.
- The Manager (Logic): This is the brain. It holds the score. When a target says, "Hey, I got hit!", the Manager updates the global score.
We’re going to create a Wrapper Class. Imagine a wrapper class as a specialized "Loot Box." Inside every box, there’s a specific item (the target device) and a specific rule (how many points it’s worth). Instead of writing the rules for every single box individually, you write the rules for the box type, then just drop the boxes into the level.
Let's Build It
We are going to build a simple shooting range.
- Good Targets: Give you points.
- Bad Targets: Take points away.
Step 1: The Setup
Open UEFN. Create a new Verse Device. Let’s call it ShootingRangeManager.
In the Details Panel for this device, you’ll see slots for other devices. This is your Scene Graph connection. You are essentially saying, "Hey, Manager, here are the targets I want you to watch."
- Drag a Target Dummy or Shooting Range Target into your level.
- Drag it into the
GoodTargetslot in your Manager device. - Drag another Target Dummy into the
BadTargetslot. - Drag a Score Manager device into the
ScoreManagerslot.
Step 2: The Code
Here is the Verse code. Don’t panic. It looks like a lot, but it’s just a bunch of instructions telling the targets how to react.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
# This is our main brain. It holds the score and knows about the targets.
shooting_range_manager_device := class(creative_device):
# The device that actually tracks the player's score.
# Think of this as the scoreboard in the lobby.
@editable
ScoreManager:score_manager_device = score_manager_device{}
# This is a "Wrapper" class. It bundles a target device with its specific rules.
# It’s like a "Loot Table" entry: here is the item, here is the value.
TargetInfo := struct:
# The actual target device in the world
Target:shooting_range_target_device = shooting_range_target_device{}
# How many points this target is worth
Points:int = 0
# Has this target already been hit in this round? (Prevents double-dipping)
IsHit:bool = false
# This function runs when the target is hit.
OnTargetHit := func():void =
# If we already hit this one, do nothing.
# It’s like trying to pick up a loot item that’s already gone.
if (IsHit?):
return
# Mark it as hit so we don’t score it again.
IsHit = true
# Disable the target visually (it disappears or goes limp).
# This is like a building piece being destroyed.
Target.Disable()
# Tell the Manager to update the score.
# If Points is negative, the score goes down!
ScoreManager.AddScore(Points)
# Optional: Reset the target after a few seconds?
# We'll leave that for Part 2.
# These are the "slots" you fill in the editor.
# You can drag multiple targets here if you want more targets.
@editable
GoodTarget1:TargetInfo = TargetInfo{Points: 100}
@editable
BadTarget1:TargetInfo = TargetInfo{Points: -50} # Negative points! Ouch.
# This is the initialization function. It runs when the game starts.
OnBegin<override>()<suspends>:void=
# Subscribe to the "Hit" event for GoodTarget1.
# This means: "Whenever GoodTarget1 gets hit, run the OnTargetHit function."
GoodTarget1.Target.HitEvent.Subscribe(GoodTarget1.OnTargetHit)
# Subscribe to the "Hit" event for BadTarget1.
BadTarget1.Target.HitEvent.Subscribe(BadTarget1.OnTargetHit)
# Wait until the game ends.
await GetWorld().GetGame().GetEndOfGameEvent().Subscribe()
Walkthrough: What Just Happened?
struct TargetInfo: This is our wrapper. Instead of managing 10 different targets with 10 different variables, we created a template. EachTargetInfoholds a reference to a device (Target) and a value (Points).OnTargetHit: This is the logic inside the wrapper. When this runs, it checksIsHit(to prevent spamming points), disables the visual target, and callsScoreManager.AddScore(Points). IfPointsis-50, the score drops.OnBegin: This is where we connect the wires. We use.Subscribe()to say, "Listen for hits on this specific target, and when they happen, run this specific function."
Why This Rocks
If you want to add a third target, you don’t write new code. You just:
- Add a new slot in the struct or class.
- Drag a new target device into the editor.
- Set the points.
It’s scalable. It’s clean. And it doesn’t crash your game when you accidentally click a target three times in one second.
Try It Yourself
Challenge: Make the bad target explode!
Right now, the bad target just disappears and takes points. Can you make it more dramatic?
- Hint 1: Look at the Bomb Flower device in the Creative toolset. It has a "Launch on Hit" option.
- Hint 2: In your
TargetInfostruct, instead of justshooting_range_target_device, you could use abomb_flower_device. - Hint 3: You’ll need to change the
Targetvariable type in the struct to match the new device.
Don’t worry if it breaks. That’s how we learn. Fix the code, press Play, and watch the chaos.
Recap
- Wrappers let you bundle data (points) with behavior (hitting) so you don’t repeat code.
- Events (
HitEvent.Subscribe) let your code react to player actions without constantly checking "did they hit it?" - Scene Graph connections (
@editablevariables) let you plug devices into your Verse logic visually.
You now have a working scoring system. Next time, we’ll add respawning targets so the game never ends. Until then, aim true.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/first-island-03-build-a-shooting-gallery-in-fortnite
- https://dev.epicgames.com/documentation/fortnite/verse-start-05-refactor-and-refine-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/grind-vine-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/grind-vine-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/first-island-05-spice-up-the-gameplay-with-verse-in-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Add Targets 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.