Magic Spawning: How to Make Props Appear with Verse
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.
Magic Spawning: How to Make Props Appear with Verse
Have you ever wanted to make a treasure chest pop into existence when you press a button? Or maybe you want to create a new enemy every few seconds? In Fortnite Creative, you usually place items by hand. But with Verse, you can write code to spawn them instantly!
Today, we will build a "Pop-Up Prize" machine. When a player steps on a special pad, a gift box will magically appear right in front of them. It is like magic, but it is actually code!
What You'll Learn
- How to find and use a Prop (a 3D object in the game).
- How to use Spawning to create new objects from thin air.
- How to place that new object at a specific Location.
- How to connect a Trigger to your Verse code.
How It Works
Imagine you are playing with LEGO bricks. Usually, you take the bricks out of the box and build your castle. The bricks are already there.
Spawning is different. It is like having a magic 3D printer. When you press a button, the printer looks at a blueprint and prints a new brick right where you need it. In Verse, we do the same thing. We tell the computer: "Take this blueprint (the Prop) and print a copy here (the Location)."
To do this, we need three things:
- The Blueprint: This is the Prop we want to spawn (like a gift box).
- The Location: The exact spot in the world where it should appear.
- The Trigger: Something that tells the code to start the magic (like a player stepping on a pad).
We will use a Player Spawn Pad. When a player touches it, our code will say "Go!" and the gift box will appear.
Let's Build It
First, let's set up your island.
- Open UEFN and create a new island.
- Place a Player Spawn Pad in the middle of your island.
- In the Content Browser (the list of items on the left), find a prop you like. A Gift Box or a Barrel is great.
- Important: We need to "register" this prop so our code knows about it. We do this by creating a Verse Script attached to the spawn pad.
- Right-click the Player Spawn Pad in the World Outliner.
- Select Add Verse Script.
- This creates a new file for your code.
Now, let's write the code. Copy this into your new Verse file.
# This is the main script for our spawning machine.
# It lives on a trigger_device placed on the island.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation }
# pop_up_prize_device is the name of our class.
# It must match the name of your Verse file exactly.
pop_up_prize_device := class(creative_device):
# A trigger_device placed in the editor.
# When a player walks into it, we get an event.
@editable
Trigger : trigger_device = trigger_device{}
# A prop_spawner_base_device placed in the editor.
# Point its "Prop Asset" field at your Gift Box in the Details Panel.
# This device handles the actual spawning for us.
@editable
GiftBoxSpawner : prop_spawner_base_device = prop_spawner_base_device{}
# OnBegin runs automatically when the game starts.
# We use it to connect our trigger to our function.
OnBegin<override>()<suspends> : void =
# Tell the Trigger: whenever a player enters, call OnPlayerEntered.
Trigger.TriggeredEvent.Subscribe(OnPlayerEntered)
# This function runs when a player touches the trigger.
# "Agent" is the person who stepped on the trigger.
OnPlayerEntered(Agent : ?agent) : void =
if (TheAgent := Agent?):
# 1. Try to get the Fortnite character for this agent.
# We need the character to read their location.
if (Character := TheAgent.GetFortCharacter[]):
# 2. Get the location of the player.
# Think of this as finding the player's feet.
PlayerTransform := Character.GetTransform()
PlayerLocation := PlayerTransform.Translation
# 3. Move the location forward a little bit.
# We don't want the box to appear *inside* the player!
# We add 100 units in front of them.
SpawnLocation := PlayerLocation + vector3{X:=100.0, Y:=0.0, Z:=0.0}
# 4. Teleport the prop_spawner_base_device to the new location,
# then fire it so a fresh copy of the prop appears there.
# prop_spawner_base_device manages its own prop asset — set that
# asset in the Details Panel under "Prop Asset".
GiftBoxSpawner.TeleportTo[SpawnLocation, IdentityRotation()]
GiftBoxSpawner.SpawnObject()```
### Walkthrough of the Code
* **`@editable Trigger`**: This is an **Editable Variable**. It lets you drag a `trigger_device` from your island into this slot in the Details Panel so the code knows which trigger to listen to.
* **`@editable GiftBoxSpawner`**: This is another **Editable Variable**. It holds a `prop_spawner_device` that you place on your island. You set *which* prop it spawns (your Gift Box) in that device's own Details Panel under **Prop Asset**.
* **`OnBegin<override>()<suspends>`**: This special function runs automatically when the game starts. We use it to wire up our event.
* **`Trigger.TriggeredEvent.Subscribe(OnPlayerEntered)`**: This is the **Connection**. It says, "Hey Trigger, whenever a player enters, run the `OnPlayerEntered` function."
* **`Agent.GetFortCharacter[]`**: This asks the computer, "Give me the actual game character for this agent." The `[]` means it can fail, so we check it with `if`.
* **`Character.GetTransform().Translation`**: This asks the computer, "Where is the player right now?" It gives us coordinates (X, Y, Z).
* **`GiftBoxSpawner.TeleportTo[...]` then `GiftBoxSpawner.Spawn()`**: These are the **Verbs**. Together they move the spawner to the right spot and then tell it to create a new copy of the prop.
### Connecting the Blueprint
The code above won't work yet because `Trigger` and `GiftBoxSpawner` are empty.
1. Place a **Trigger Device** and a **Prop Spawner Device** on your island in UEFN.
2. Click on the **pop_up_prize_device** actor in your World Outliner.
3. Look at the **Details Panel** (usually on the right).
4. Find the Verse Script component.
5. You will see fields called `Trigger` and `GiftBoxSpawner`.
6. Drag your **Trigger Device** from the World Outliner into the `Trigger` slot.
7. Drag your **Prop Spawner Device** into the `GiftBoxSpawner` slot.
8. Select the **Prop Spawner Device** itself, and in *its* Details Panel set the **Prop Asset** field to your Gift Box.
9. Click **Compile** (the green checkmark) in the Verse button menu. If it turns green, you did it!
Now, test your island. Step on the pad. Watch as a gift box pops into existence!
## Try It Yourself
You made a box appear! Now, let's make it cooler.
**Challenge:** Can you make the box appear *above* the player instead of in front of them?
**Hint:** Look at the line where we calculate `SpawnLocation`. We added `X:=100.0`. Try changing that to `Z:=100.0` instead. What does Z represent in 3D space? (Think up and down!)
## Recap
* **Spawning** creates new objects from code, just like a 3D printer.
* We need a **Blueprint** (the prop asset) and a **Location** (where to put it).
* **Functions** are blocks of code that run when something happens, like a player entering a zone.
* Always compile your code to check for errors.
You just wrote your first spawning code! You can now create traps, power-ups, and endless enemies. Keep experimenting and have fun building!
## References
* https://dev.epicgames.com/documentation/en-us/uefn/verse-prop-hunt-template-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/uefn/user-interface-reference-for-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/uefn/25.00-release-notes-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/25-00-release-notes-in-unreal-editor-for-fortnite
* https://dev.epicgames.com/documentation/en-us/fortnite/prop-hunt-template-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Spawning props and actors from Verse code 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.