How to Build a "Mercenary Mode" Island with Verse
Tutorial beginner compiles

How to Build a "Mercenary Mode" Island with Verse

Updated beginner Code verified

How to Build a "Mercenary Mode" Island with Verse

You know how boring it is when you drop into a zone and there's literally no one else around but a few bots that stand still until you poke them? Yeah, we're fixing that. In this tutorial, we're going to build a Mercenary Mode island using Verse.

Instead of just placing static enemies, we'll write code that lets players hire a squad of elite guards to fight alongside them. These guards won't just stand there like decorative statues; they'll patrol, detect players, and actually team up to take down targets. It's like bringing your own raid squad into a solo lobby. Let's get coding.

What You'll Learn

By the end of this tutorial, you will know how to:

  • Use Verse to interact with Fortnite's Guard Spawner device.
  • Understand the Scene Graph (the family tree of objects in your game).
  • Create a Variable to track whether a player has "hired" their guards.
  • Build a simple Event that triggers when a player presses a button to summon their squad.

How It Works

Before we touch the code, let's break down the logic using mechanics you already know.

The Guard Spawner: Your Personal Respawn Pad for Enemies

Think of the Guard Spawner device like a specialized Player Spawn Pad. Normally, Player Spawn Pads create you (the hero). The Guard Spawner creates them (the NPCs).

But here's the twist: unlike a standard Player Spawn Pad that just dumps you into the map, the Guard Spawner creates entities that have AI (Artificial Intelligence). They have vision, they move, and they fight. They are the difference between a static turret and a teammate who actually covers your flank.

The Scene Graph: Who's Who in the Family Tree

In Fortnite Creative, everything you place is part of the Scene Graph. Imagine the Scene Graph as your Party List in a squad game.

  • The Island is the lobby.
  • The Guard Spawner is a player in that lobby.
  • The Guards are the actual characters spawned by that player.

In Verse, we don't just "find" a spawner. We have to tell Verse exactly which "player" (device) in the party list we are talking about. If you have ten Guard Spawners on your map, Verse needs to know which one to activate. We do this by referencing the device in the Scene Graph.

Variables: The "Hired" Status

We need a way to remember if a player has already paid for their guards. If they press the button twice, do they get double the guards? Probably not. That's where a Variable comes in.

A Variable is like a Health Bar or a Shield Meter. It holds a value that can change. In our case, we'll use a Boolean Variable (a simple True/False switch).

  • True = Guards are hired/active.
  • False = No guards hired yet.

When the player presses the "Summon" button, we check the Variable. If it's False, we spawn the guards and flip it to True. If it's True, we ignore the button press (or maybe refund them, but let's keep it simple).

Let's Build It

We are going to build a system where:

  1. A player walks up to a Button.
  2. They press it.
  3. Verse checks if they have already hired guards.
  4. If not, Verse tells the Guard Spawner to spawn a squad of Ghosts.
  5. Verse updates the Variable so they can't spam the button for infinite guards.

Step 1: Place Your Devices

  1. Place a Player Spawner (where you start).
  2. Place a Guard Spawner somewhere in the map. Let's call it MyGuardSpawner.
  3. Place a Button near the start. Let's call it SummonButton.
  4. (Optional) Place a Timer set to 30 seconds if you want the guards to despawn after a while, but for this basic tutorial, we'll let them live forever until you reset the island.

Step 2: The Verse Code

Open the Verse editor for your island. We'll write a script that connects the Button to the Guard Spawner.

# Import the necessary libraries for devices and game logic
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is our main script file. Think of it as the "Brain" of the island.
# It inherits from creative_device, which is the real base class for
# island scripts that interact with placed devices in UEFN.
my_mercenary_script := class(creative_device):

    # --- THE VARIABLES (The "Stats") ---

    # This variable tracks if the player has hired guards.
    # It starts as "false" (not hired).
    # 'var' makes it mutable so we can flip it later.
    var HasHiredGuards : logic = false

    # This is a reference to the Guard Spawner device.
    # In the UEFN editor, drag your placed Guard Spawner device
    # into this property slot to wire it up.
    @editable
    GuardSpawnerRef : guard_spawner_device = guard_spawner_device{}

    # This is the Button device.
    # In the UEFN editor, drag your placed Button device into this slot.
    @editable
    SummonButtonRef : button_device = button_device{}

    # --- THE SETUP (When the game starts) ---

    # This function runs once when the island loads.
    OnBegin<override>()<suspends> : void =
        # We want to listen for when the button is pressed.
        # This is like setting up a "Trigger" in the device editor, but in code.
        # We connect the Button's InteractedWithEvent to our handler below.
        # InteractedWithEvent sends the agent (player) who pressed the button.
        SummonButtonRef.InteractedWithEvent.Subscribe(HandleButtonPress)

        # Log a message to the debug console (optional, for testing)
        Print("Mercenary Mode Ready. Press the button to hire guards!")

    # --- THE LOGIC (What happens when the button is pressed) ---

    # This function is called when the button is pressed.
    # InteractedWithEvent passes the agent who triggered it.
    HandleButtonPress(Agent : agent) : void =
        # Check if the player has already hired guards.
        # In Verse, 'logic' values are tested with 'if (Var?)' or compared directly.
        if (HasHiredGuards = false):
            # If they haven't, we spawn the guards!
            # Enable() tells the Guard Spawner to spawn its configured guards.
            # The Guard Spawner device spawns however many guards you configured
            # in its device properties in the editor (set "Guard Count" there).
            # note: guard_spawner_device has no Spawn(n) method; use Enable() to trigger spawning.
            GuardSpawnerRef.Enable()

            # Now, we update the variable to "true".
            # This prevents the player from spawning more guards by pressing the button again.
            set HasHiredGuards = true

            # Print a message to the player (or debug log)
            Print("Guards hired! They are now patrolling.")
        else:
            # If they already hired guards, tell them to stop spamming.
            Print("You already hired your squad! Wait for them to finish or reset.")

Walkthrough: What Just Happened?

  1. my_mercenary_script := class(creative_device): This defines our script. Think of it as creating a new "Hero" class in a RPG. It's the container for all our logic. creative_device is the real Verse base class for island scripts in UEFN.
  2. var HasHiredGuards : logic = false: This is our Variable. It's like a switch on the wall. Initially, it's off. The var keyword is required in Verse to make a field mutable — without it, you can never change the value after initialization.
  3. OnBegin<override>(): This is the Event that fires when the game starts. It's like the "Round Start" announcer. We use this to set up our connections.
  4. SummonButtonRef.InteractedWithEvent.Subscribe(HandleButtonPress): This is the magic line. We are telling Verse: "Whenever the Button is pressed, run the HandleButtonPress function." This is Event Binding. In device terms, it's like connecting a wire from the Button's "On Pressed" output to the input of our code. InteractedWithEvent is the real event name on button_device.
  5. GuardSpawnerRef.Enable(): This is where the guards appear. Enable() is the real method on guard_spawner_device that triggers it to spawn its guards. You control how many guards spawn by setting the Guard Count property directly on the device in the UEFN editor.
  6. set HasHiredGuards = true: We flip the switch. In Verse, mutating a var field requires the set keyword. Now, if the player presses the button again, the if block won't run and nothing will happen.

Try It Yourself

Challenge: Right now, once you hire your guards, they stay forever. That's great for a permanent defense, but what if you want a "Mercenary Contract" that only lasts for 60 seconds?

Hint: You can use a Timer device in combination with Verse. Or, even cooler, you can use Verse's Sleep() function to pause the code for a specific amount of time, then despawn the guards. Try to modify the HandleButtonPress function to:

  1. Spawn the guards.
  2. Wait for 60 seconds.
  3. Set HasHiredGuards back to false so the player can hire them again.

(Don't worry, I won't give you the full solution. Try it out! If you get stuck, check the Verse documentation on Sleep and Time.)

Recap

You just built a dynamic mercenary system using Verse! You learned how to:

  • Use Variables to track game state (like whether guards are hired).
  • Connect Events (Button Press) to Functions (Spawn Logic).
  • Interact with Devices (Guard Spawner) to spawn AI entities.
  • Understand the Scene Graph by referencing specific devices in your code.

Now go make some islands where players feel like actual raid leaders. And remember: if your guards start dancing instead of fighting, check your device settings.

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/using-guard-spawner-devices-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-guard-spawner-devices-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/create-a-music-experience-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/create-a-music-experience-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/post-process-device-design-examples-in-fortnite

Verse source files

Turn this into a guided course

Add using-guard-spawner-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.

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