The "Loot Goblin" Trap: How to Make Weapons Chase Players in Verse
The "Loot Goblin" Trap: How to Make Weapons Chase Players in Verse
So you've built the map, you've placed the loot, and now you're staring at a static pistol sitting on a crate like it's waiting for a bus that left ten minutes ago. Boring. In Fortnite, chaos is king, and nothing says "chaos" like a weapon that refuses to stay put.
In this tutorial, we're going to build a Loot Goblin. It's a simple Verse script that grabs a weapon entity from the scene, waits for a player to get close, and then teleports the weapon to a new random spot on the map. It's not just moving a prop; it's teaching you how Verse talks to the game world using Entities and Events. By the end, you'll have a weapon that actively runs away from (or toward) players, making your island feel alive and unpredictable.
What You'll Learn
- Entities: Understanding that everything in Verse (weapons, players, props) is an "Entity" you can manipulate.
- Events: How to listen for gameplay moments (like "Player Entered Trigger") without constant checking.
- Scene Graph Basics: How to find specific items in your level hierarchy.
- Movement & Teleportation: The difference between moving an object over time and snapping it to a new location instantly.
How It Works
Think of your Fortnite island as a giant, messy backpack. Inside that backpack are thousands of items: walls, floors, NPCs, and weapons. In programming terms, we call this collection of all active objects in the game world the Scene Graph. Every single thing you place in UEFN is an Entity (an object that exists in the game world).
To make a weapon move, we need to do three things:
- Find the Weapon: We need to tell Verse, "Hey, find me that specific Tactical Pistol I placed in the editor." We do this by looking through the Scene Graph.
- Listen for Trouble: We don't want to check every frame if a player is near. That's inefficient. Instead, we use an Event. An Event is like a tripwire. You set it up, and Verse says, "Call this function only when something happens." In our case, the "something" is a player entering a specific area.
- Make It Move: Once the event triggers, we grab the weapon's current position, pick a new random spot, and snap the weapon there.
The Scene Graph: Your Level's Family Tree
In Unreal Engine and Verse, objects aren't floating in a void; they are organized in a hierarchy. This is the Scene Graph. Imagine your island is a folder structure on your computer.
- The World is the root folder.
- Actors (like your players, NPCs, and placed props) are files inside that folder.
- Components are the attributes of those files (the mesh, the collision box, the damage type).
When you place a weapon in UEFN, it becomes an Entity in this graph. To control it with Verse, we need a reference to it. We don't just say "the pistol"; we say "the Entity named MyLootGoblinPistol." This is crucial. If you name your prop something generic like Box_01, Verse won't know which one you mean if you have fifty boxes. Name your props!
Events vs. Loops: The Tripwire Analogy
New programmers often try to use Loops to check for players. A loop is like having a guard patrol your house every second, checking every window. It works, but it's exhausting and slow.
Events are like installing a motion sensor. The sensor does nothing most of the time (saving CPU power), but the moment someone crosses the threshold, it rings the bell. In Verse, we attach a function to an Event. When the event fires, our function runs once. It's cleaner, faster, and less likely to crash your island.
Let's Build It
We are going to create a Verse script that lives inside a Trigger Volume (a invisible box). When a player enters the box, the script finds a weapon entity, calculates a new random position nearby, and teleports the weapon there.
Step 1: Set Up Your Level
- Open UEFN and create a new island or open an existing one.
- Place a Trigger Volume device in the middle of a room. Make it big enough to catch players.
- Place a Creature Spawner or Prop to act as a stand-in marker for your goblin weapon's starting location. We will reference the trigger device directly in Verse.
- Crucial Step: Select the Trigger Volume device in the editor. In the Details Panel, find the Verse section. Click the dropdown to assign a new Verse script. Name it
LootGoblinScript. - Place a second Trigger Volume device that will represent the weapon's "spawn anchor" — or simply note the coordinates you want the weapon to bounce between.
Step 2: The Verse Code
Open the LootGoblinScript editor. Here is the complete code. Read the comments carefully—they explain the "why" behind the syntax.
# LootGoblinScript.verse
# This script makes a creative prop teleport when a player enters a trigger.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# 2. DEFINING THE DEVICE
# In UEFN, Verse scripts attached to the level are creative_device subclasses.
# We expose the trigger device so it can be wired in the editor Details Panel.
loot_goblin_script := class(creative_device):
# 3. EDITABLE REFERENCES
# Drag your Trigger Device and prop_manipulator_device into these slots
# in the UEFN Details Panel.
@editable
Trigger : trigger_device = trigger_device{}
# prop_manipulator_device lets us move a placed creative prop at runtime.
# Wire this to a Prop Manipulator device placed on your weapon prop.
@editable
GoblinProp : prop_manipulator_device = prop_manipulator_device{}
# 4. ENTRY POINT
# OnBegin runs once when the island starts. We use it to subscribe to events.
OnBegin<override>()<suspends> : void =
# Subscribe our handler to the trigger's TriggeredEvent.
# Every time a player enters the trigger, OnPlayerEntered is called.
Trigger.TriggeredEvent.Subscribe(OnPlayerEntered)
# 5. EVENT HANDLER
# This function is called automatically each time the trigger fires.
# 'Agent' is the player (or NPC) who entered. We cast it to fort_character.
OnPlayerEntered(Agent : ?agent) : void =
if (ActualAgent := Agent?):
# Cast agent to fort_character so we can read their position.
if (Character := ActualAgent.GetFortCharacter[]):
# 6. CALCULATE NEW POSITION
# Get the character's current world transform, then extract translation.
CurrentTransform := Character.GetTransform()
CurrentLoc := CurrentTransform.Translation
# Create a random offset so the weapon jumps near — but not inside — the player.
# GetRandomFloat returns a float in [Low, High].
RandomX := GetRandomFloat(-500.0, 500.0)
RandomY := GetRandomFloat(-500.0, 500.0)
RandomZ := 0.0 # keep the prop on the same horizontal plane
NewLocation := vector3:
X := CurrentLoc.X + RandomX
Y := CurrentLoc.Y + RandomY
Z := CurrentLoc.Z + RandomZ
# 7. TELEPORT THE PROP
# prop_manipulator_device.TeleportTo moves the linked prop instantly.
# The second argument is a rotation; we pass the current rotation unchanged.
NewTransform := transform:
Translation := NewLocation
Rotation := CurrentTransform.Rotation
Scale := vector3{X:=1.0, Y:=1.0, Z:=1.0}
if (GoblinProp.TeleportTo[NewTransform]):
# Optional: trigger a visual/audio cue here for player feedback!```
### Walkthrough: What Just Happened?
1. **`loot_goblin_script := class(creative_device)`**: This defines our device as a proper UEFN creative device — the real base class for all Verse scripts attached to an island. We pass references in through `@editable` fields wired in the editor, instead of constructor arguments.
2. **`OnBegin<override>()<suspends>`**: This is Verse's true entry point for a `creative_device`. It runs once at island start. We use it to subscribe our handler to the trigger's built-in `TriggeredEvent`.
3. **`Trigger.TriggeredEvent.Subscribe(OnPlayerEntered)`**: This is our **Event** hookup. Instead of polling every frame, we register a callback. Verse calls `OnPlayerEntered` exactly once per player entry — efficient and clean.
4. **`Agent.GetFortCharacter[]`**: Casts the generic `agent` the trigger reports into a `fort_character`, which exposes position and gameplay methods. The `[]` suffix marks this as a failable expression, handled by the surrounding `if`.
5. **`GetRandomFloat(-500.0, 500.0)`**: Generates a random float in the given range. We use this to create a "jitter" effect, so the weapon doesn't just slide; it hops unpredictably near the player.
6. **`GoblinProp.TeleportTo(NewTransform)`**: `prop_manipulator_device` is the real UEFN device for moving placed props at runtime. `TeleportTo` snaps the prop to the provided `transform` instantly — no interpolation.
## Try It Yourself
You've got the basics down. Now, let's make it more chaotic.
**Challenge**: Modify the script so that the weapon doesn't just teleport to a spot near the *triggering* player, but instead teleports to a **different random player's location** each time.
**Hint**:
1. Use `GetPlayspace().GetPlayers()` to retrieve all active players on the island.
2. Pick a random index with `GetRandomInt(0, Players.Length - 1)` to select a target.
3. Add a small random offset to that player's position so the weapon doesn't land *inside* their feet (which might cause clipping or weird physics).
*Don't worry if it doesn't work immediately. Debugging is part of the fun. Check your console for error messages — they're like elimination notices, telling you exactly where you went wrong.*
## Recap
* **Entities** are all the objects in your game world. You control them by finding them in the Scene Graph.
* **Events** like `TriggeredEvent` let you react to gameplay moments efficiently, without wasting resources on constant checks.
* **Variables** store data (like positions) that changes during the game.
* **Functions** like `TeleportTo` and `GetTransform` are your tools for interacting with the engine.
You've just built your first interactive Verse system. It's not just a static prop anymore; it's a living part of your island. Next time you play, imagine what other "goblins" you can create. Maybe a loot box that runs away when you get close? The possibilities are endless.
## References
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/weapons/tacticalpistol_br_ch4s1_common
- https://dev.epicgames.com/documentation/en-us/fortnite/fortnite-creative/verse-api/fortnitedotcom/itemization/lastresortitems/item_tactical_dmr_common
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/weapons/tacticalpistol_br_ch7s1_common
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/weapons/submachinegun_og_ch1s1_common
- https://dev.epicgames.com/documentation/fortnite/verse-api/fortnitedotcom/weapons/tacticaldmr_br_ch4s4_uncommon
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add General 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.