The Ultimate "Oh Crap" Button: Building a Portable Item Dispenser
Tutorial beginner compiles

The Ultimate "Oh Crap" Button: Building a Portable Item Dispenser

Updated beginner Code verified

The Ultimate "Oh Crap" Button: Building a Portable Item Dispenser

You've been holding that Launchpad in your inventory for twenty minutes, waiting for the perfect moment to escape a shrinking storm circle. But then—oops. You threw it, missed the ledge, and now you're eating storm damage while your teammates laugh. It's the worst feeling in Fortnite.

What if you could build a machine that spits out Launchpads, Port-A-Forts, and Repair Torches on command? No more digging through your inventory. No more missed throws. Just pure, unadulterated chaos.

In this tutorial, we're going to build a Portable Item Dispenser. It's a simple device that gives players a specific portable consumable when they press a button. It's the difference between panicking and playing like a pro.

What You'll Learn

  • Variables: How to store a "choice" in your code (like choosing which loot drop to spawn).
  • Functions: How to package a set of actions (pick item, give item) into one reusable command.
  • Events: How to make code react when a player does something (like pressing a button).
  • Scene Graph Basics: Understanding how your code "talks" to the items in your world.

How It Works

Before we touch any code, let's map this to mechanics you already know.

Imagine you are the Game Director. Your job is to decide what happens when a player presses a button.

  1. The Trigger: A button on the wall. This is an Event. In game terms, it's like the storm timer hitting zero. Something happened.
  2. The Logic: Your code decides what to give. This is a Function. Think of a function like a specific move in a fighting game. You press "Down, Down, Forward + Punch," and the character performs a Hadouken. The code is the input; the item grant is the move.
  3. The Actor: The player who presses the button. In programming, we call this the Caller or Player.
  4. The Item: The actual object being handed over. This is stored in a Variable. A variable is just a box with a label on it. If the label says "Launchpad," the box contains a Launchpad. If you change the label to "Port-A-Fort," the box now contains a Fort.

We aren't just hard-coding one item. We're going to write code that lets you pick which portable item the dispenser gives, making it a reusable tool for any island.

Let's Build It

We need three things in your Creative Placing Menu:

  1. A Button: Any button works (e.g., "Button"). Place it on a wall.
  2. A Player: Obviously, you need someone to press it.
  3. The Code: A Verse Script.

Here is the complete, annotated code for the dispenser.

# This is a Verse Script. It lives inside a device on your map.
# Think of this script as the "brain" of your dispenser.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# We create a "Device" class. This is the blueprint for our dispenser.
# In the Scene Graph, this device is a node that holds our logic.
dispenser_device := class(creative_device):

    # --- VARIABLES: The "Loot Box" ---
    # A reference to the button device placed on your map.
    # In the UEFN Outliner, set this property to point at your button_device.
    @editable
    DispenserButton : button_device = button_device{}

    # A reference to the item granter device that actually hands items to players.
    # Place an item_granter_device on your map, configure its item in the UEFN
    # Details panel (e.g. Launchpad, Port-A-Fort, Repair Torch), then wire it here.
    # Change which device you point at to change the loot — no code edits needed!
    @editable
    ItemGranter : item_granter_device = item_granter_device{}

    # --- FUNCTIONS: The "Combo Moves" ---
    # This function takes a player and tells the item granter to give them the item.
    # It's like a vending machine: Insert Coin (Player) -> Get Snack (Item).
    GivePortableItem(Agent : agent) : void =
        # item_granter_device.GrantItem requires an agent, which every player is.
        # This is like pulling the specific can of soda from the shelf and handing it over.
        ItemGranter.GrantItem(Agent)

        # Optional: log a message to the UEFN Output Log so you know it fired.
        # note: player.PrintToScreen does not exist in Verse; Print() writes to the log.
        Print("Dispenser: item granted to agent.")

    # --- EVENTS: The "Storm Timer" ---
    # OnBegin runs once when the level starts.
    # It's like the match starting — we set up our triggers here.
    OnBegin<override>()<suspends> : void =
        # Connect the button's InteractedWithEvent to our function.
        # When the button is pressed, run GivePortableItem with the agent who pressed it.
        # This is the core loop: Press -> Trigger -> Action.
        DispenserButton.InteractedWithEvent.Subscribe(GivePortableItem)```

### Walkthrough: What Just Happened?

1.  **`@editable DispenserButton`**: This is your **Variable** for the trigger. Marking a field `@editable` makes it appear as a slot in the UEFN Details panel, so you can drag your in-world button device straight into it  no string look-ups required.
2.  **`@editable ItemGranter`**: This is your **Variable** for the loot. An `item_granter_device` is a real UEFN device you drop on the map and configure in its Details panel (pick the item, set the count). Swapping which device you point this field at changes what the dispenser gives  it's like swapping the ammo type in your gun.
3.  **`GivePortableItem`**: This is your **Function**. It does one specific thing: tell the granter to give its configured item to whoever triggered the button. You could call this function from anywhere in your code and it would always do the same job.
4.  **`OnBegin`**: This is an **Event**. It runs once when the level starts. We use it to "wire up" the button by subscribing `GivePortableItem` to `InteractedWithEvent`. We tell the game: "Hey, when this button is pressed, take the agent who pressed it and feed them to the `GivePortableItem` function."

## Try It Yourself

You've got the basics. Now, let's make it more chaotic.

**Challenge:** Modify the code above to create a "Random Loot Goblin" dispenser.

**Hint:**
1.  Instead of one `ItemGranter` variable, create a list (array) of multiple `item_granter_device` references (e.g., one granter configured for Launchpad, one for Port-A-Fort, one for Rift-To-Go).
2.  Use a random number generator to pick one granter from that list.
3.  Call `GrantItem` on that randomly chosen granter.

*Don't worry if you get stuck! The key is to think about how you'd pick a random card from a deck. You need a deck (the list) and a shuffle (the random pick).*

## Recap

You just built a functional item dispenser using Verse. You learned how **Variables** store data (like device references), how **Functions** package actions (like giving an item), and how **Events** trigger those actions (like pressing a button). This is the foundation of all Fortnite Creative logic. From here, you can build traps, game modes, and entire islands.

## References

- https://dev.epicgames.com/documentation/en-us/fortnite/using-portable-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-portable-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-travel-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/exploring-the-content-browser-menu-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-portable-items-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.

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.

Comments

    Sign in to vote, comment, or suggest an edit. Sign in