The Magic Backpack: Building Your First Item Pickup
The Magic Backpack: Building Your First Item Pickup
Do you want players to find a glowing keycard and use it to open a secret door? In Fortnite, items aren't just static objects. They are part of a player's backpack. We will build a custom item. It will sit on the ground. Players can pick it up. It will go into their inventory. This makes your island feel like a real game.
What You'll Learn
- What a Component is.
- How to give an object item powers.
- How to use Verse to check if a player has an item.
- How to make a door open when the right item is used.
How It Works
Think of your game world like a toy box. Inside are different toys. Some toys are just blocks. They sit there. They do nothing. Other toys are action figures. They have special powers. Maybe they can fly. Maybe they can shoot lasers.
In Fortnite, we use Components to give objects powers. A component is like a sticker you put on a toy. It adds a new ability.
We have two main stickers here.
- The Look Sticker: This tells the game what the item looks like. It has a 3D shape. It has an icon for the backpack.
- The Pickup Sticker: This tells the game how to handle the item. When a player looks at it, a prompt appears. When they press the button, the item disappears from the ground. It appears in the player's inventory.
We will also use Verse. Verse is the code that runs the game logic. We will write a small script. This script checks one thing. Does the player have the keycard? If yes, the door opens. If no, the door stays shut.
This system uses the Scene Graph. The Scene Graph is the family tree of your game. Every object is a node. Components are attached to these nodes. This keeps everything organized.
Let's Build It
We will build a simple puzzle. There is a locked door. There is a keycard on the floor. The player picks up the keycard. They walk to the door. The door opens.
First, you need to set up your project in UEFN. You need a Player Spawner. You need a Door device. And you need an Item.
We will create a custom Verse Component. This component will handle the logic. It will watch for the door interaction. It will check the player's inventory.
Here is the Verse code. It is simple and clean.
# We import the tools we need from Fortnite.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
# GetFortCharacter is defined in /Fortnite.com/Characters
using { /Fortnite.com/Characters }
# This is our keycard door manager device.
# It lives alongside a door_device placed on the island.
keycard_door_manager := class(creative_device):
# Wire this to the Door device in the UEFN editor.
@editable
Door : lock_device = lock_device{}
# Wire this to the Item Spawner device in the UEFN editor.
@editable
KeycardSpawner : item_spawner_device = item_spawner_device{}
# OnBegin runs once when the game starts.
OnBegin<override>()<suspends> : void =
# We print a message to the console.
# This helps us know the code is running.
Print("The door is waiting for a keycard.")
# We listen for the item spawner's pickup event.
# When a player picks up the keycard, we fire our check.
KeycardSpawner.ItemPickedUpEvent.Subscribe(OnKeycardPickedUp)
# This function runs when a player picks up the item from the spawner.
OnKeycardPickedUp(Agent : agent) : void =
# Cast agent to fort_character so we can use player APIs.
# GetFortCharacter is a fallible call (<decides>), so we use the [] operator
# to handle the failure case (if the agent is not a fort_character).
if (Character := Agent.GetFortCharacter[]):
Print("Keycard picked up! Opening the door.")
# Open the door for the agent who picked up the keycard.
Door.Open(Agent)
else:
Print("Something picked up the keycard, but it was not a player.")```
### Walkthrough of the Code
Let's look at each part.
`keycard_door_manager := class(creative_device)`
This line defines our new device class. It is called `keycard_door_manager`. It inherits from `creative_device`. Every Verse device in UEFN starts this way. It gives the class a home in your island.
`@editable Door : door_device`
This declares a variable called `Door`. The `@editable` tag makes it appear in the UEFN editor panel. You drag and drop your Door device into this slot. The code and the object are now connected.
`@editable KeycardSpawner : item_spawner_device`
This does the same thing for the Item Spawner. You wire it up in the editor. No item names need to be typed by hand. The connection is visual and reliable.
`OnBeginPlay()`
This function runs once. It runs when the game starts. We use it to print a message. This is good for debugging. It tells us the code is active. We also call `Subscribe` here. This tells the game to watch for pickup events.
`KeycardSpawner.ItemPickedUpEvent.Subscribe(OnKeycardPickedUp)`
This is the listening line. `ItemPickedUpEvent` is a real event on `item_spawner_device`. Every time a player picks up the item, the game calls our `OnKeycardPickedUp` function automatically.
`OnKeycardPickedUp(Agent : agent)`
This function runs when a player picks up the item from the spawner. It receives the `agent` who did the picking up. We cast them to a `fort_character` to confirm they are a real player character.
`Door.Open(Agent)`
This tells the door device to open. It passes in the agent so the door knows who triggered it. The door swings open for that player.
## Try It Yourself
You have the code. Now you need to set up the objects.
1. Place a **Door** device in your island.
2. Place an **Item Spawner** device near the door. Configure it to spawn your custom keycard item.
3. Add your new `keycard_door_manager` Verse device to the island.
4. Select the `keycard_door_manager` device. In the editor details panel, wire the **Door** slot to your Door device. Wire the **KeycardSpawner** slot to your Item Spawner device.
5. Play your island. Walk to the door. Try to open it without the keycard. Then pick up the keycard. Watch the door open.
**Hint:** If the door doesn't open, check your editor wiring first. Make sure both slots in the details panel are filled. Then check the console for print messages. They tell you what the code is seeing.
## Recap
You built a working item system. You learned about Components. You learned how Verse watches for item pickup events. You made a door that responds to player inventory. This is a big step. You are no longer just placing objects. You are creating game logic. Keep building. Keep coding. Your island is ready for players.
## References
- https://dev.epicgames.com/documentation/en-us/fortnite/create-an-item-pickup-interactable-component-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-custom-keycard-item-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/39-30-fortnite-ecosystem-updates-and-release-notes
- https://dev.epicgames.com/documentation/en-us/fortnite/custom-inventory-and-items-overview-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-healing-items-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add create-an-item-pickup-interactable-component-in-fortnite 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.