Throw Power: Making Attack Consumables in UEFN
Tutorial beginner compiles

Throw Power: Making Attack Consumables in UEFN

Updated beginner Code verified

Throw Power: Making Attack Consumables in UEFN

Do you want to throw Cuddle Fish that explode? Do you want to drop Storm Flips that change the weather? You can make this happen in Fortnite Creative!

In this tutorial, we will build a simple item dispenser. Players will walk up to it. They will press a button. They will get a powerful attack item. This is like a vending machine for battle gear.

We will use Verse to make it work. You do not need to be a math expert. You just need to follow the steps. Let's start building your own battle station!

What You'll Learn

  • What a Consumable is. It is an item you use once. It disappears after you use it.
  • How to give items to players. We will use a "Grant Item" device.
  • How to use Verse. We will write a small script to connect the button to the item.
  • Scene Graph basics. We will look at how devices talk to each other in your island.

How It Works

Think of your island like a toy box. Inside the box are many toys. Some are static, like a plastic tree. Some are active, like a remote-control car.

In UEFN, we call these toys Entities. An entity is any object in your game. It can be a wall, a player, or a button.

Each entity has parts called Components. Think of components as accessories. A button has a "Trigger" component. A dispenser has a "Grant Item" component.

To make them work together, we need a brain. That brain is Verse. Verse is the language that tells the button what to do when you press it.

We will build a "Cuddle Fish Dispenser." When you press the button, the dispenser gives you a Cuddle Fish. Then you can throw it at your friends!

Let's Build It

Follow these steps carefully. You will build the island first, then add the code.

Step 1: Place the Devices

Open UEFN and create a new island. Place these two devices on the ground:

  1. Button Device: Place a "Button" device. This is what players will press.
  2. Grant Item Device: Place a "Grant Item" device next to it. This is the machine that gives the item.

Step 2: Set Up the Grant Item

Click on the Grant Item device. Look at its properties on the right side.

  1. Find the Item property.
  2. Click the dropdown menu.
  3. Search for "Cuddle Fish."
  4. Select it. Now the device knows to give a Cuddle Fish.

Step 3: Connect Them with Verse

Now we write the code. This code tells the Button to tell the Grant Item to work.

Copy this code into a new Verse file. Save it next to your island.

# This is our main script file.
# It connects the button to the item dispenser.

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

# We define a new "Thing" called CuddleDispenser.
# A "Thing" is a container for our code.
# creative_device is the real base class for island scripts in Verse.
cuddle_dispenser := class(creative_device):

    # This is the button player will press.
    # We link it to the Button device in the editor.
    @editable
    MyButton : button_device = button_device{}

    # This is the device that gives the item.
    # We link it to the Grant Item device.
    @editable
    MyGranter : item_granter_device = item_granter_device{}

    # This function runs when the game starts.
    # It sets up the connection.
    OnBegin<override>()<suspends> : void =
        # We wait for the button to be pressed.
        # When it is pressed, we run the "GiveItem" function.
        MyButton.InteractedWithEvent.Subscribe(GiveItem)

    # This function actually gives the item.
    # InteractedWithEvent passes the agent (player) who pressed the button.
    GiveItem(Agent : agent) : void =
        # The "Agent" is the player who pressed the button.
        # We tell the granter to give an item to that player.
        MyGranter.GrantItem(Agent)

This step is very important. The code needs to know which devices to use.

  1. Place a Verse Device on your island.
  2. Click the Verse Device.
  3. In the properties panel, find the Script field.
  4. Select the Verse file you just saved.
  5. Now, find the MyButton and MyGranter fields in the properties.
  6. Drag the Button device from your island into the MyButton slot.
  7. Drag the Grant Item device into the MyGranter slot.

Step 5: Test Your Island

Play your island! Walk up to the button. Press it. You should see a Cuddle Fish appear in your inventory. Pick it up. Throw it!

You just made a working game mechanic with code. Great job!

Try It Yourself

You made a Cuddle Fish dispenser. Now try to make it harder.

Challenge: Change the code or settings so the dispenser gives a Storm Flip instead.

Hint: You only need to change one setting in the Grant Item device. Look back at Step 2. What did you change there? Do it again with the Storm Flip item.

Recap

You learned how to use Verse to connect devices. You learned that Entities are objects in your game. You learned that Components are the parts that make them do things. You also learned how to give players attack consumables like Cuddle Fish.

Keep experimenting. Try adding a timer. Try making the button reset. You are now a creator!

References

  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-attack-consumables-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/using-attack-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/fortnite-glossary
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-produce-consumables-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-attack-consumables-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