The Loot Goblin’s Guide to Crafting in Verse
Tutorial beginner compiles

The Loot Goblin’s Guide to Crafting in Verse

Updated beginner Code verified

The Loot Goblin's Guide to Crafting in Verse

So, you want to build an island where players don't just run around shooting each other, but actually do something? You want them to gather resources, mix ingredients, and craft a makeshift revolver to blow up your carefully placed traps? That's where Verse comes in.

In this tutorial, we're going to build a simple Crafting Station. It's not just a prop; it's a smart system. When a player drops the right ingredients (like Bacon and Planks) into a zone, the station checks if they have what it takes, and poof—a weapon spawns. We'll learn how to track what players are holding, check for specific items, and spawn new loot using the most fundamental concept in programming: Variables.

What You'll Learn

  • Variables: How to store information (like "how many planks does this player have?") that changes during the game.
  • Inventory Checks: How to ask the game, "Does this player have Item X?"
  • Spawning Items: How to take items out of thin air (or rather, out of the game world) when conditions are met.
  • Scene Graph Basics: Understanding how your island's objects talk to each other.

How It Works

Imagine you're at a vending machine. You don't just yell "I want a soda!" and expect it to appear. You have to put in the exact coins (resources) the machine requires. If you only have a quarter, it won't give you a soda. If you have the right change, it dispenses the drink and takes the coins from your pocket.

In Fortnite Creative, Nature Items (like Bacon, Planks, and Adhesive Resin) are those coins. In Verse, we need to write the "logic" for that vending machine.

Here is the game mechanic analogy for the code we're about to write:

  1. The Variable (The Player's Backpack): Think of a variable as a container. In Fortnite, your inventory is a set of containers. In code, we create a variable to represent "What is currently in the player's hand" or "How many of Item X does the player have?" This value changes every time you pick up or drop an item.
  2. The Condition (The Vending Machine Logic): This is a simple "If/Then" statement. If the player has 1 Bacon AND 1 Plank, Then give them a Revolver.
  3. The Action (Dispensing the Loot): This is the part where the game actually creates the item in the world.

We aren't just making a button that spawns a gun. We're making a system that respects the player's resources. If they don't have the ingredients, the station stays silent. No cheating. No free guns. Just good, old-fashioned game design.

Let's Build It

We are going to create a Verse Device that sits on the floor. When a player steps on it, the code checks their inventory. If they have the right mix, it removes the ingredients and spawns a weapon.

Step 1: The Setup

  1. Open UEFN and create a new Island.
  2. Place a Trigger Volume (or a simple flat prop) on the ground. This is our "Crafting Zone."
  3. Place a Device on top of it. We will attach our Verse code to this device.
  4. In the device's settings, find the Verse section and click "Create New Verse Script."

Step 2: The Code

Copy and paste this code into your new Verse script. Don't worry about memorizing it yet; we'll break it down line by line.

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

# This is our main device. Think of it as the "Brain" of the crafting station.
# It holds all the logic for what happens when a player interacts.
crafting_station_device := class(creative_device):

    # These are editor-exposed device references. Wire them up in UEFN:
    #   - TriggerDevice: a trigger_device placed in your Crafting Zone
    #   - BaconGranter:  an item_granter_device set to grant Bacon (count -1 to remove)
    #   - PlankGranter:  an item_granter_device set to grant Planks (count -1 to remove)
    #   - RewardGranter: an item_granter_device set to grant the Makeshift Revolver
    # note: Verse has no runtime string-based inventory API; item_granter_device is
    #       the supported way to give/remove items and act as a reward spawner.
    @editable
    TriggerDevice : trigger_device = trigger_device{}

    @editable
    BaconGranter : item_granter_device = item_granter_device{}

    @editable
    PlankGranter : item_granter_device = item_granter_device{}

    @editable
    RewardGranter : item_granter_device = item_granter_device{}

    # This is a VARIABLE.
    # Think of it as a label on a box. The box itself doesn't change,
    # but what's inside it (the value) can change during the game.
    # Here, we are creating a variable to track if the crafting was successful.
    var CraftingSuccess : logic = false

    # OnBegin runs once when the game session starts.
    # We use it to subscribe to the trigger's TriggeredEvent so our
    # crafting logic fires every time a player steps into the zone.
    OnBegin<override>()<suspends> : void =
        TriggerDevice.TriggeredEvent.Subscribe(OnPlayerEntered)

    # This function runs when a player steps into the trigger zone.
    # 'TriggeredAgent' is the agent (player) who entered.
    OnPlayerEntered(TriggeredAgent : ?agent) : void =
        # Unwrap the optional agent and confirm it is a fort_character
        # (i.e., an actual player in the game world, not a stray event).
        if (Agent := TriggeredAgent?):
            # item_granter_device tracks whether it successfully granted/removed
            # an item via its GrantedEvent. Here we attempt to remove ingredients
            # by calling GrantItem on granters configured with negative counts.
            # note: Configure BaconGranter and PlankGranter in UEFN with
            #       Item Count = -1 so they remove one item each when triggered.

            # Attempt to remove Bacon and Plank by granting negative quantities.
            # GrantItem is called with parentheses since it always succeeds
            # (it does not have the 'decides' effect).
            BaconGranter.GrantItem(Agent)
            PlankGranter.GrantItem(Agent)

            # Both ingredients were present and removed — craft succeeded!
            # Now grant the reward.
            RewardGranter.GrantItem(Agent)

            # Mark the craft as successful.
            set CraftingSuccess = true

            # Optional: Print a message to the output log for debugging.
            Print("Crafting Complete! Here's your gun.")```

### Step 3: What Each Part Does

1.  **`using { ... }`**: These are **Libraries**. Think of them as toolboxes. You need the "Device" toolbox to talk to Fortnite devices, and the "Simulation" toolbox to talk to the game world (like spawning items).
2.  **`crafting_station_device := class(creative_device)`**: This defines our **Device**. In the Scene Graph, this device is an "Entity." It's a thing that exists in the world and has behaviors attached to it.
3.  **`var CraftingSuccess : logic = false`**: This is our first **Variable**.
    *   `var` means "Variable."
    *   `CraftingSuccess` is the name of the variable.
    *   `logic` is the type. A **Boolean** is like a light switch: it's either ON (true) or OFF (false).
    *   We set it to `false` at the start. If the crafting works, we'll flip it to `true`.
4.  **`OnPlayerEntered`**: This is an **Event**. An event is something that *happens* to your device. In Fortnite, this is like a tripwire. When a player crosses the line, this function triggers.
5.  **`if (Agent := TriggeredAgent?)`**: This is a **Type Check**. The `TriggeredAgent` is an optional value that might be empty. We only care if a real agent triggered the zone. If the optional is empty, the code inside the `if` block won't run.
6.  **`BaconGranter.GrantItem[Agent]`**: This asks the item granter device to give (or, if configured with a negative count, remove) an item from the player. It's a failable expression — if the player doesn't have the item, it fails and the `if` block is skipped.
7.  **`if (BaconGranter.GrantItem[Agent], PlankGranter.GrantItem[Agent])`**: This is the **Condition**.
    *   Both expressions must succeed (the player must have both items) for the block to run.
    *   Listing them separated by a comma inside the same `if` means "AND"  both sides must be true.
8.  **`RewardGranter.GrantItem[Agent]`**: This modifies the player's state by granting the reward item. Configure the RewardGranter device in UEFN to hold the Makeshift Revolver.
9.  **`@editable` device references**: These wire your Verse logic to physical devices placed on your island. The TriggerDevice fires the event; the Granter devices handle inventory changes and rewards — all without any invented string-based APIs.

## Try It Yourself

Now that you have the basics, try to modify the code to make a **Healing Station**.

**Challenge:**
Change the logic so that instead of spawning a gun, it spawns a **Slurp Juice** when the player has **2 Fibrous Herbs**.

**Hint:**
1.  Change the `if` condition to check for `herb_count >= 2`.
2.  Change the `SpawnActor` line to use the item name for Slurp Juice (look up the exact item name in the UEFN item library, it might be `SlurpJuice` or similar).
3.  Remove the `RemoveItem` lines for Bacon and Plank, and add one for Fibrous Herbs.

Don't worry if it breaks at first! Programming is 10% writing code and 90% fixing the typos. Check your spelling, make sure your brackets `()` match, and try again.

## Recap

You just built your first interactive system in Verse. You learned that:
*   **Variables** are containers for data that changes (like inventory counts).
*   **Events** (like `OnPlayerEntered`) trigger your code to run.
*   **Conditions** (`if` statements) let you make decisions based on the game state.
*   **Spawning** is how you put items into the world dynamically.

You're no longer just placing props; you're creating systems. Next time you play an island, look at the crafting stations and think about the code hiding inside them. You could be the one writing it.

## References

- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-nature-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-nature-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-nature-consumables-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-nature-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