The Magic Coin Machine: How Collectibles Work in Verse
The Magic Coin Machine: How Collectibles Work in Verse
Do you like finding hidden treasures? Do you like getting cool items just for picking them up? In Fortnite Creative, we can make that happen! We will build a simple machine. It turns a shiny coin into a fun item. You will learn how to talk to the game using Verse. Let's make magic happen!
What You'll Learn
- What a Collectible Object is.
- How to use Verse to make items change.
- How to give players rewards.
- How to connect devices together.
How It Works
Imagine you are playing a video game. You see a gold coin. You jump on it. Poof! You get a jetpack. That is what we are building!
In Fortnite, there are special boxes called Devices. Think of a device like a remote control for the game world. One device is the Collectible Object. This is the thing you pick up. Another device is the Item Granter. This is the machine that gives you stuff.
We need a bridge between them. That bridge is Verse. Verse is a language. It tells the devices what to do. It says, "When someone picks up the coin, give them the jetpack."
Here is the plan. We will place a coin in the world. We will write a small script. The script listens for the coin. When the coin is taken, the script sends a signal. The Item Granter hears the signal. It gives the player a reward. Simple, right? Let's code it!
Let's Build It
First, open UEFN. Go to the Devices tab. Search for "Collectible Object". Place one on the floor. Search for "Item Granter". Place it nearby. Now, let's write the code.
Copy this code into a new Verse file. Make sure to name your devices in the editor! Name the Collectible Object MyCoin and the Item Granter MyRewards.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our main script.
# It connects the coin to the reward.
MyCollectibleScript := class(creative_device):
# Bind MyCoin in the UEFN editor by selecting this device
# and assigning the Collectible Object to this property.
@editable
MyCoin : collectible_object_device = collectible_object_device{}
# Bind MyRewards in the UEFN editor by selecting this device
# and assigning the Item Granter to this property.
@editable
MyRewards : item_granter_device = item_granter_device{}
# This part runs when the game starts.
OnBegin<override>()<suspends>: void=
# We listen for when the coin is picked up.
# 'MyCoin' must be assigned in your editor's Details panel.
MyCoin.CollectedEvent.Subscribe(OnCoinPicked)
Print("Coin is ready! Go get it!")
# This function runs when the coin is picked.
# CollectedEvent sends the agent (player) who picked it up.
OnCoinPicked(Collector : agent): void=
# Give the player their reward via the Item Granter.
# The Item Granter device grants whichever item
# you configured in its own Details panel in the editor.
# Note: item_granter_device has no runtime item-name API;
# set the item inside the device's settings in UEFN.
MyRewards.GrantItem(Collector)
Print("You got a Boogie Bomb!")
Walkthrough
Let's look at the code line by line.
using { /Fortnite.com/Devices }: This line says, "Hey Verse, let me use Fortnite devices." It is like grabbing your favorite toy from the shelf.MyCollectibleScript := class(creative_device): This creates a new script. Think of it as a new rulebook for your game. It extendscreative_deviceso UEFN can place it in the world.@editable: This tag makes a device slot appear in the UEFN editor. You drag your placed device into that slot so the code can find it.OnBegin: This is the start button. When the game loads, this part runs first.MyCoin.CollectedEvent.Subscribe(OnCoinPicked): This is the magic link. It says, "When the coin is picked up, run theOnCoinPickedfunction."CollectedEventis the real event fired bycollectible_object_device.MyRewards.GrantItem(Collector): This tells the Item Granter to give an item to the player who triggered the event. The item itself is chosen inside the Item Granter's settings panel in UEFN — not passed as a string in code.
Try It Yourself
You did it! You made a coin give you an item. Now, try this challenge.
Challenge: Change the code so the coin gives you a Shield Potion instead of a Boogie Bomb.
Hint: Look at your Item Granter device in the UEFN editor. Open its Details panel and change the item it is set to grant to a Shield Potion. Save your code and test it in your island!
Recap
You learned how to use Verse to connect devices. You used a Collectible Object as the trigger. You used an Item Granter as the reward. You wrote code to link them together. Great job, coder!
References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-collectible-object-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-collectibles-object-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/design-a-prop-hunt-game-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/devices/collectible_object_device
- https://dev.epicgames.com/documentation/en-us/fortnite/design-a-prop-hunt-game-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-collectibles-object-devices-in-fortnite-creative 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.