The "Light Switch" Heist: Building a Prefab Puzzle in Verse
Tutorial beginner

The "Light Switch" Heist: Building a Prefab Puzzle in Verse

Updated beginner

The "Light Switch" Heist: Building a Prefab Puzzle in Verse

So, you’ve got a loot stash you don’t want the other team to find. Sure, you could just hide it behind a wall of stone, but that’s boring. Real pros use logic. In this tutorial, we’re going to build a Tagged Lights Puzzle. Think of it like a high-tech vault door: players have to flip the right sequence of light switches to unlock the prize.

We’re not just placing static lights; we’re using Prefabs (reusable blueprints) and Verse (the code that makes things happen). By the end, you’ll have a reusable puzzle module you can drop into any island, whether it’s a battle royale map or a creative obby. No more guessing which button does what—just pure, coded chaos.

What You'll Learn

  • Prefabs: How to create a "blueprint" for your puzzle pieces so you can duplicate them without breaking the original.
  • Scene Graph Hierarchy: Understanding how objects are organized in a tree structure (like folders in your inventory).
  • State Management: Using a variable to track which lights are on or off, similar to tracking health or shield bars.
  • Event Handling: Writing code that reacts when a player interacts with a button, like a trigger pad that launches you into the sky.

How It Works

Before we touch the code, let’s look at the architecture. In UEFN, everything exists in the Scene Graph. Imagine the Scene Graph as your island’s file explorer. You have folders (Groups) and files (Entities). An Entity is any object in your world—a light, a button, a player, or a whole building.

We are going to build a Prefab. A prefab is like a saved screenshot of a setup, but with a twist: if you change the original, every copy updates. It’s the difference between editing one text file that updates ten websites, versus copying and pasting text into ten different Word docs.

Here is the game plan:

  1. The Button: When a player clicks it, it sends a signal.
  2. The Light: It receives the signal and toggles its state (On/Off).
  3. The Logic: We need a central "brain" (a Verse script) that watches all the lights. If all lights are On, it triggers the reward.

In programming terms, we need a Variable. A variable is just a container for data that can change. Think of it like your Shield Bar. It starts at 0, goes up to 100, and changes based on what happens. Our variable will be a list (or array) that tracks the state of each light: True for On, False for Off.

We also need Events. An event is a moment in time that the game notices. In Fortnite, this is when you step on a trigger pad. In Verse, we’ll create a custom event: OnButtonPressed. When this happens, our code updates the variable and checks if the puzzle is solved.

Let's Build It

Step 1: Set Up Your Prefab

  1. Open UEFN and create a new group called PuzzlePrefab.
  2. Inside it, place a Static Light (set it to "On" initially) and a Button device nearby.
  3. Select both, right-click, and choose Create Prefab. Name it LightSwitchUnit.
  4. Delete the original instances. You now have a clean prefab asset.

Step 2: Create the Verse Script

We need a script that lives on the parent entity (the container holding all your puzzle pieces). Let’s call this entity PuzzleController.

Create a new Verse file named LightPuzzle.v. Paste this code in. Don’t worry, we’ll break it down line by line.

# This is our main script. It defines the behavior of our puzzle.
# Think of this as the "Game Rules" document for this specific puzzle.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# This is our Prefab type. It represents one light/switch unit.
# We use this to tell Verse: "Hey, these lights belong together."
type LightUnit is data {
    # A reference to the light device in the scene graph.
    # This is like pointing to a specific folder in your inventory.
    LightDevice: light_device
    
    # A reference to the button that controls it.
    ButtonDevice: button_device
    
    # The current state: true = ON, false = OFF.
    # This is our variable! It changes every time someone clicks.
    IsOn: bool = false
}

# This is the main controller. It holds a list of all our LightUnits.
# Imagine this is the "Master Control Panel" for your vault.
type PuzzleController is data {
    # A list of all the light switches in this puzzle.
    # We use a list because we might have 3 lights, or 10.
    Lights: list<LightUnit> = list{}
    
    # This is the reward! An item granter that gives the loot.
    RewardItem: item_granter_device
}

# This is the "Brain" of our operation.
# It runs when the puzzle starts.
on_begin<override>()<suspends> = (
    # We need to find all our LightUnits in the Scene Graph.
    # This loops through every entity in our group.
    for unit : Scene.GetEntities<LightUnit>() {
        # Add each found unit to our master list.
        Lights = append(Lights, unit)
        
        # Connect the button to our logic.
        # When the button is pressed, run the ToggleLight function.
        unit.ButtonDevice.OnButtonPressed += func(): void {
            ToggleLight(unit)
        }
    }
)

# This function handles the logic for a single button press.
# It’s like a mini-program inside the main program.
ToggleLight = func(unit: LightUnit) {
    # Flip the state: if it was true, make it false, and vice versa.
    # This is the core mechanic!
    unit.IsOn = not unit.IsOn
    
    # Update the visual light.
    # If IsOn is true, turn the light on. If false, turn it off.
    if (unit.IsOn) {
        unit.LightDevice.SetLightOn(true)
    } else {
        unit.LightDevice.SetLightOn(false)
    }
    
    # Check if the puzzle is solved!
    CheckWinCondition()
}

# This function checks if ALL lights are currently ON.
CheckWinCondition = func() {
    # Assume we haven't won yet.
    all_on: bool = true
    
    # Look at every light in our list.
    for unit : Lights {
        # If even ONE light is off, we can't win.
        if (not unit.IsOn) {
            all_on = false
            break # Stop checking immediately, no need to keep going.
        }
    }
    
    # If we got here and all_on is still true, everyone is lit up!
    if (all_on) {
        # Give the player the reward.
        # This spawns the item in the player's inventory.
        RewardItem.GrantItem()
        
        # Optional: You could also play a sound or open a door here.
    }
}

Step 3: Wiring It Up

  1. In the Scene Graph, select your PuzzleController entity.
  2. In the Details panel, find the Verse Script component and assign the LightPuzzle script to it.
  3. Now, for each LightSwitchUnit prefab you placed in the world:
    • Select the prefab instance.
    • In the Details panel, find the Verse Data section.
    • Drag your actual Light Device into the LightDevice slot.
    • Drag your actual Button Device into the ButtonDevice slot.
  4. On the PuzzleController, drag your Item Granter into the RewardItem slot.

How the Code Works

  • type LightUnit is data: This creates a custom object. It’s like defining a new card in your deck. This card has three stats: the Light, the Button, and the State (IsOn).
  • on_begin: This is the "Game Start" event. Verse runs this once when the level loads. It scans the world for any entities marked as LightUnit and adds them to the Lights list. It’s like the referee checking the roster before the match starts.
  • ToggleLight: This is the action. When a button is pressed, we flip the IsOn variable. If it was false, it becomes true. Then we tell the physical light device to match that state.
  • CheckWinCondition: This is the victory screen trigger. It loops through every light in the list. If it finds a single light that is false, it breaks. If it finishes the loop without breaking, it means every light is true, and it grants the item.

Try It Yourself

You’ve built the basic vault. Now, make it harder.

Challenge: Add a "Reset" button. Create a new button in your puzzle room. When pressed, it should turn all lights OFF and reset the IsOn variable for every unit back to false.

Hint: You’ll need to add another event handler in on_begin for the reset button, similar to how we handled the toggle buttons. Inside the reset function, you’ll need to loop through the Lights list again and set each unit’s state to false and call SetLightOn(false).

Recap

You just built a dynamic puzzle system using Prefabs for easy management and Verse for logic. You learned how variables track state (like health bars), how events trigger actions (like stepping on a pad), and how to use loops to check conditions (like checking if all storm windows are closed). This foundation is the key to building complex game modes, from escape rooms to battle royale objectives.

References

  • https://dev.epicgames.com/documentation/en-us/uefn/tagged-lights-puzzle-in-verse
  • https://dev.epicgames.com/documentation/en-us/fortnite/tagged-lights-puzzle-in-verse
  • https://dev.epicgames.com/documentation/en-us/fortnite/scene-graph-tutorials-in-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/getting-started-in-scene-graph-in-fortnite
  • https://dev.epicgames.com/documentation/en-us/fortnite/create-your-own-device-in-verse

Verse source files

Turn this into a guided course

Add lights-and-bridges-05-create-a-puzzle-with-prefabs-in-fortnite 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