Code the Storm: How to Program Dynamic Lighting in Fortnite
Code the Storm: How to Program Dynamic Lighting in Fortnite
So you’ve got a spooky island, but the lighting looks like it was set by a blindfolded artist. You want lights that change color when you eliminate an enemy, or spotlights that follow players like a director with a caffeine addiction. That’s where Verse comes in. It’s the coding language that lets you turn static props into dynamic, reactive game systems.
In this tutorial, we’re going to build a "Mood Ring Trap." When a player steps on a specific tile, the lights in the room will shift from "calm blue" to "danger red." We’ll learn how to use variables to store light colors and functions to trigger changes, all without touching a single paintbrush.
What You'll Learn
- Variables: How to store a color value so you can change it later (like saving a loadout).
- Device Interaction: How to make a device listen for player input.
- Functions: How to group instructions together so your code stays clean (like a combo move).
- Lighting Logic: The difference between Point Lights and Spotlights and how to control them.
How It Works
Before we write a single line of code, let’s map this to Fortnite mechanics you already know.
1. The Device is Your Controller
Think of a Customizable Light device as a remote control for a lightbulb. In the editor, you place it. It has settings (color, intensity, range). But right now, it’s stuck on "Manual Mode." We need to switch it to "Remote Mode" so our code can hit the buttons for it.
2. Variables are Your Inventory Slots
In Fortnite, you have inventory slots. You can put a shield potion in Slot 1, then swap it for a medkit. A Variable in Verse is exactly like that slot. It’s a named container that holds a piece of data.
- The Data: In our case, the data is a Color.
- The Name: We’ll call our variable
TrapColor. - The Change: Initially,
TrapColoris Blue. When the trap triggers, we change the value inside the slot to Red.
3. Functions are Your Emote Wheel
You don’t press a button for every single animation frame of "Floss." You press the emote wheel, select "Floss," and the game runs a pre-made sequence of actions. In Verse, a Function is a named block of code that does a specific job. We’ll create a function called SetTrapState that takes a color as an ingredient and turns all the lights that color.
4. Scene Graph: The Hierarchy of Stuff
In Unreal Editor for Fortnite (UEFN), everything exists in a Scene Graph. Think of this like the hierarchy of a squad.
- The Island is the Team Leader.
- The Room is a Squad Member.
- The Light Device is the individual Player.
To talk to the light, you have to know its position in the hierarchy. In Verse, we usually grab devices by their "Name" (the name you gave them in the editor, like Light_01).
Let's Build It
Step 1: Set Up the Stage
- Open UEFN and create a new Creative project.
- Place a Customizable Light device. Let’s call it
MainLightin the Name field (in the Details panel). - Set its type to Spotlight (it looks cooler for traps) and aim it at the center of the room.
- Place a Trigger Volume (or a simple floor tile with a Trigger device) in front of the light. Let’s call the Trigger
TrapTrigger.
Step 2: The Verse Code
Create a new Verse script. We’ll keep it simple. We need to:
- Reference the light device.
- Define a function to change its color.
- Listen for the trigger.
Here is the code. Don’t panic at the syntax; we’ll break it down line-by-line.
// We are defining a script that runs on an object (like the Trigger)
script class LightTrapScript:
// 1. VARIABLES: These are like your inventory slots.
// We need to connect to the device named "MainLight" in the editor.
// 'MainLight' must match the Name field in UEFN exactly.
MainLight: CustomizableLightDevice = CustomizableLightDevice(MainLight)
// 2. FUNCTIONS: This is our "Combo Move."
// It takes a 'Color' as input and changes the light.
// Think of 'Color' as the ammo you feed into the function.
func SetLightTo(color: Color) -> void:
// This line sends a signal to the device to change its color.
// It's like pressing the 'Change Color' button on the remote.
MainLight.SetColor(color)
// Optional: Log a message to the debug console to prove it worked.
#print(f"Light changed to {color}")
#event OnBegin():
#print("Trap armed! Waiting for players...")
#event OnStart():
#print("Script started.")
// 3. EVENTS: These are triggered by game actions.
// OnTriggered fires when someone walks into our Trigger Volume.
#event OnTriggered(Other: Actor):
// Check if the thing that triggered it is a Player.
if (Other.IsPlayer()):
#print(f"{Other.GetDisplayName()} triggered the trap!")
// Call our function and pass in the color RED.
// In Verse, we use the built-in Color struct.
SetLightTo(Color(255, 0, 0, 255))
// Note: Color is (R, G, B, Alpha). 255,0,0 is pure red.
// Bonus: Let's make it reset if the player leaves?
// For now, let's just make it toggle if you want to get fancy later.
Walkthrough: What Just Happened?
script class LightTrapScript:: This tells UEFN, "Hey, I’m writing a script, and this is what it’s called." It’s like naming your save file.MainLight: CustomizableLightDevice: This is the Variable definition. We are creating a slot namedMainLightand telling Verse, "This slot holds a Customizable Light Device." We assign itCustomizableLightDevice(MainLight), which links it to the device named "MainLight" in your level. If you named your device "Light_01" in UEFN, you must changeMainLighttoLight_01here, or the code won’t find it.func SetLightTo(color: Color) -> void:: We defined a Function. It accepts one piece of data: aColor. It returnsvoid(nothing), because its job is just to do something, not give us a number back.MainLight.SetColor(color): This is the magic line. It calls a method (a built-in action) on our device variable. It says, "HeyMainLight, take thecolorvariable I just gave you, and set your internal color to that."#event OnTriggered(Other: Actor):: This is the Event. It waits for someone to step on the trigger. TheOthervariable is the person who stepped on it.SetLightTo(Color(255, 0, 0, 255)): We call our function. We pass it aColorstruct.255, 0, 0is Red. The last255is Alpha (opacity). We are essentially saying, "Run theSetLightTofunction, and use Red as the ingredient."
Try It Yourself
You’ve got the basics. Now, make it cooler.
Challenge: Modify the script so that when the player triggers the trap, the light doesn’t just turn Red—it turns Purple (255, 0, 255, 255) and then switches back to Blue (0, 0, 255, 255) after 2 seconds.
Hint: You’ll need to use a Timer. In Verse, you can use CreateTimer or Delay (depending on the specific API version you’re using in UEFN, often CreateTimer is the robust way). Or, simpler: just create two functions, SetPurple and SetBlue, and call them in sequence? (Wait, that won’t work for a delay). Look up how to use CreateTimer in Verse to call a function after a delay.
Hint 2: If you get stuck, remember: Variables store the state, Functions perform the action, and Events start the chain reaction.
Recap
- Variables are like inventory slots; they hold data (like a Color) that can change.
- Functions are like emote combos; they group actions together so you can reuse them.
- Events (like
OnTriggered) are the game moments that kick off your code. - Scene Graph naming matters: Your Verse variable must link to the exact name of the device in UEFN.
Now go make your island look like a AAA title, not a Minecraft mod. And remember: if the lights don’t change, check your spelling. Verse is case-sensitive. MainLight is not mainlight.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-customizable-light-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-customizable-light-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/lighting-starter-island-template-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/lighting-starter-island-template-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/using-devices-in-fortnite
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add using-customizable-light-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.
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.