Build a "What If?" History Engine: Rewriting Time with Verse
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/elsestatements 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:
- The Variable (
Mode): This is like your Current Loadout. It’s a single piece of data that remembers what you picked. Is it0(Medieval) or1(Cyber)? It stays with you until you change it. - 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. - 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.
- Create a Parent Entity named
Medieval_Props. - Place a few medieval-looking props (stone walls, torches) inside it.
- Create another Parent Entity named
Cyber_Props. - Place some neon lights, metal ramps, and holograms inside it.
- Place two Switches (or Buttons) on the island. Name them
Btn_MedievalandBtn_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?
var MainGame: This creates a "container" for our game logic. Think of it as the Inventory Screen. It holdsCurrentTheme, which is just a number.0means Medieval,1means Cyber.ApplyTheme(): This is the Gadget. When called, it checksCurrentTheme. If it’s0, it hides the Medieval group and shows the Cyber group. It’s like opening a chest and getting a different item. Theif/elsestatement is the Decision Tree you see in quest lines.ThemeButton: This script is attached to your buttons. When you hit the button, it tellsMainGameto runApplyTheme(). 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."
- Create a
Space_Propsentity in the editor with some zero-gravity looking props. - Add a third button in the editor.
- Modify the
CurrentThemevariable logic to handle0,1, and2. - Hint: You’ll need to expand your
if/elsechain. It’s like adding more options to your loadout menu. IfCurrentThemeis1, go toSpace. If it’s2, go back toMedieval.
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
- 01-fragment.verse · fragment
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.
References
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.