Build a "What If?" History Engine: Rewriting Time with Verse
Tutorial beginner

Build a "What If?" History Engine: Rewriting Time with Verse

Updated beginner

Build a "What If?" History Engine: Rewriting Time with Verse

So, you’ve mastered the storm timer and you can make a button that spawns a shotgun. Boring. Let’s do something that actually makes your brain hurt in a good way.

We’re going to build a "Counterfactual History Engine." No, that’s not a fancy sci-fi weapon. It’s a programming concept where you change one variable in the past, and the whole future changes. Think of it like this: In Fortnite, if you don’t loot the chest, you don’t get the shield potion. Your "future" (surviving the storm) changes based on that one past action.

In this tutorial, we’ll use Verse (Epic’s programming language for Fortnite islands) to create a system where a player’s choice at the start of the round literally rewrites the island’s layout. One button builds a medieval castle; another builds a cyberpunk city. It’s not just a skin swap; it’s a total scene-graph overhaul triggered by a single decision.

What You'll Learn

  • Variables as Inventory Slots: How to store a "state" (like "Medieval Mode" or "Cyber Mode") that persists across the game.
  • The Scene Graph as a Backpack: Understanding how Fortnite organizes props and how we can swap entire groups of them out.
  • Functions as Gadgets: Writing a reusable block of code that handles the heavy lifting of changing the world.
  • Conditional Logic as Loadouts: Using if/else statements to decide which "loadout" of props gets spawned based on the player's choice.

How It Works

Imagine you’re standing in front of two doors. Door A leads to a dungeon. Door B leads to a space station. In traditional Fortnite Creative, you’d have to build both, hide them, and use triggers to show/hide them. That’s messy. That’s like carrying a full build box just to place one wall.

In Verse, we treat the Scene Graph (the hierarchy of all objects in your island) like a dynamic inventory. We don’t just "hide" props; we tell the game engine to detach the "Medieval" group from the world and attach the "Cyberpunk" group.

Here is the game-mechanic translation:

  1. The Variable (Mode): This is like your Current Loadout. It’s a single piece of data that remembers what you picked. Is it 0 (Medieval) or 1 (Cyber)? It stays with you until you change it.
  2. The Function (ApplyTheme): This is like your Rebirth Van. You call it, it does a bunch of stuff (destroys old props, spawns new ones), and then you’re ready to go.
  3. The Event (OnPlayerJoined): This is the Battle Bus Drop. It’s the moment the game starts, and we need to check if the player made a choice before they even touched the ground.

We aren’t just changing colors. We are changing the structure of the island. This is where the Scene Graph shines. By grouping props under a parent entity, we can move, delete, or spawn them as a single unit, just like moving a stack of building pieces.

Let's Build It

We are going to build a simple "Theme Chooser." You’ll place two buttons. When a player hits one, the island transforms.

Step 1: The Setup (In-Editor)

Before we code, we need our "props" ready.

  1. Create a Parent Entity named Medieval_Props.
  2. Place a few medieval-looking props (stone walls, torches) inside it.
  3. Create another Parent Entity named Cyber_Props.
  4. Place some neon lights, metal ramps, and holograms inside it.
  5. Place two Switches (or Buttons) on the island. Name them Btn_Medieval and Btn_Cyber.

Step 2: The Verse Code

Open the Verse editor for a new script. We’ll keep it tight. We need to define our "Loadout" variable and the function that swaps the world.

# We need to import the basic tools to talk to the game world
using { /Fortnite.com/Devices }
using { /UnrealEngine.com temporary/Engine }

# This is our main script, attached to the island
# Think of this as the "Game Master" entity
# It holds the state of the game
[CreateByRef]
var MainGame: {
    # This variable is our "Current Theme"
    # It’s like your current weapon slot. 
    # We start with "Medieval" (represented by 0)
    CurrentTheme: int = 0

    # This function is the "Rebirth Van"
    # It takes no input, but it changes the world
    # It's a "procedure" because it does something rather than returns a value
    ApplyTheme() -> void:
        # First, we hide the current theme
        # If CurrentTheme is 0, we hide Medieval_Props
        # If CurrentTheme is 1, we hide Cyber_Props
        # We use a simple check, like deciding which path to take at a fork in the road
        if (CurrentTheme == 0):
            # Get the Medieval props group
            # We assume we have a reference to this entity in our editor setup
            # In a real build, you'd link this via the editor's "Variable" tab
            Medieval_Props.SetVisibility(Visibility: Hidden)
            
            # Now, show the Cyber props
            # This is like swapping your shield potion for a chug splash
            Cyber_Props.SetVisibility(Visibility: Visible)
            
            # Update our "Loadout" variable to remember we are now in Cyber mode
            CurrentTheme = 1
        else:
            # If we are already in Cyber mode, we go back to Medieval
            Cyber_Props.SetVisibility(Visibility: Hidden)
            Medieval_Props.SetVisibility(Visibility: Visible)
            CurrentTheme = 0

    # This event fires when the game starts
    # It’s like the "Ready Up" screen
    OnBegin<override>()<suspends>:
        # When the game begins, make sure everything is hidden first
        Medieval_Props.SetVisibility(Visibility: Hidden)
        Cyber_Props.SetVisibility(Visibility: Hidden)
        
        # Wait for player input...
        # We'll handle the button clicks in a separate event or loop
        # For simplicity, we'll just wait here for now
        Wait(1.0)
}

# This is the "Trigger" for our buttons
# We attach this script to the Switches in the editor
[CreateByRef]
var ThemeButton: {
    # Reference to the MainGame script so we can change its theme
    MainGame: MainGame

    # This event fires when the button is pressed
    OnActivated<override>()<suspends>:
        # Call the MainGame's function to swap the world
        MainGame.ApplyTheme()
        
        # Optional: Give the player a little feedback
        # Like the sound effect when you pick up a keycard
        MainGame.BroadcastMessage("Theme Changed!")
}

Walkthrough: What Just Happened?

  1. var MainGame: This creates a "container" for our game logic. Think of it as the Inventory Screen. It holds CurrentTheme, which is just a number. 0 means Medieval, 1 means Cyber.
  2. ApplyTheme(): This is the Gadget. When called, it checks CurrentTheme. If it’s 0, it hides the Medieval group and shows the Cyber group. It’s like opening a chest and getting a different item. The if/else statement is the Decision Tree you see in quest lines.
  3. ThemeButton: This script is attached to your buttons. When you hit the button, it tells MainGame to run ApplyTheme(). It’s like pressing the A button to interact with a device.

Try It Yourself

You’ve got the basics. Now, make it chaotic.

Challenge: Add a third theme, "Space Station."

  1. Create a Space_Props entity in the editor with some zero-gravity looking props.
  2. Add a third button in the editor.
  3. Modify the CurrentTheme variable logic to handle 0, 1, and 2.
  4. Hint: You’ll need to expand your if/else chain. It’s like adding more options to your loadout menu. If CurrentTheme is 1, go to Space. If it’s 2, go back to Medieval.

Don’t forget to link your new button to the ThemeButton script in the editor!

Recap

You just built a dynamic world-switcher using Verse. You learned that variables are like your inventory slots (remembering what you picked), functions are like gadgets (doing the work), and conditional logic is like choosing a path in a quest. By manipulating the Scene Graph (the hierarchy of props), you can completely change the feel of your island without rebuilding it from scratch.

Now go make some history. Or rewrite it. Whatever you prefer.

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/humanities-arts-and-design-lesson-plans-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-landing-humanities-arts-design-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/education-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/education-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/science-engineering-and-math-lesson-plans-in-fortnite-creative

Verse source files

Turn this into a guided course

Add humanities-arts-and-design-lesson-plans-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