Pick Your Fighter: Building a Class Selector in Verse
Pick Your Fighter: Building a Class Selector in Verse
Ever wanted to build a Fortnite island where players don’t just spawn as generic soldiers, but actually get to pick their role—like a Tank, a Sniper, or a chaotic Jester—before the storm even starts? That’s the power of Classes.
In this tutorial, we’re going to build a system where players choose their "loadout personality" from a sleek UI menu (or a map tab) and get equipped with the exact weapons, items, and stats that match their choice. No more guessing games. You’re the architect, and now you’re handing out the blueprints.
What You'll Learn
- What a "Class" is: Think of it as a character class in an RPG (Warrior, Mage, Rogue), but in Fortnite Creative. It’s a container that holds specific weapons, items, and stats.
- The Scene Graph Connection: How devices talk to each other in the hierarchy (the "who tells whom" chain).
- The Two-Part System: Why you need a Class Designer (the definition) and a Class Selector (the menu).
- Verse Basics: How to write the simple script that connects your UI to the gameplay.
How It Works
Before we touch any code, let’s break down the mechanics using things you already know.
1. The "Class" is Your Loadout Card
Imagine you’re in the lobby. You have a "Class" selected. If you pick Tank, your loadout card says: Shotgun, Shield Potion, 200 HP. If you pick Sniper, it says: Sniper Rifle, Cloak, 100 HP. In Fortnite Creative, a Class is just a named list of things. You define it once, then you can assign it to players whenever they want.
2. The Designer vs. The Selector
This is where beginners get tripped up. You need two different devices, and they have different jobs:
- The Class Designer (The Chef): This is where you cook up your classes. You go into the editor, create a class called "Jester," and drag a Party Gun and a Jester’s Hat into it. The Designer doesn’t do anything during gameplay; it’s just the settings menu.
- The Class Selector (The Waiter): This is what the player sees. It can be a popup dialog (like when you pick your emote) or a tab on the Map screen. When a player clicks "Jester," the Selector tells the game: "Hey, give that player the Jester loadout!"
3. The Scene Graph: Who Talks to Whom?
In Unreal Engine (and Verse), everything exists in a Scene Graph. Think of this like a family tree or a chain of command.
- Entities are the people in the tree (Players, Devices, Props).
- Components are their skills or items.
- Hierarchy is who reports to whom.
When you place a Class Selector UI device in your island, it’s an Entity. It has a function (a skill) called OnSelected. When a player clicks a class, that function fires. But the Selector doesn’t know how to change the player’s items. That’s why we need a tiny bit of Verse code to bridge the gap between "Player clicked Jester" and "Player gets Party Gun."
Let's Build It
We’re going to build a simple "Class Picker" that appears when the game starts. We’ll use the Class Selector UI device for the menu, and a bit of Verse to make sure the player actually gets the items they picked.
Step 1: Set Up Your Classes (The Designer)
- Place a Class Designer device in your island (it doesn’t need to be visible to players).
- Open its properties. Create two classes:
Class: Hero-> Add a Shotgun and a Shield Potion.Class: Villain-> Add a Sniper Rifle and a Cloak.
- Save your island.
Step 2: Place the Menu (The Selector)
- Place a Class Selector UI device somewhere convenient (or hide it).
- In its properties, set the Classes dropdown to include
HeroandVillain. - Choose your UI style: Popup Dialog (appears over the screen) or Map Tab (appears in the bottom corner). Let’s go with Popup Dialog for immediate feedback.
Step 3: The Verse Code (The Glue)
Now, we need to tell the game what to do when a player picks a class. We’ll create a simple Verse script that listens for the selection event.
Create a new Verse file in your project. Name it ClassPicker.v.
using { /Fortnite.com/Devices }
# This is our main "Controller" device.
# It will sit in the world and listen for class selections.
class ClassPickerController < creative_object:
# We need a reference to the UI device we placed in the editor
# Think of this as plugging a microphone into a speaker.
selector_device: ClassSelectorUIDevice = ClassSelectorUIDevice{}
# This function runs when the game starts
OnBegin<override>()<suspends>: void =
# 1. Listen for when a player selects a class
selector_device.SelectedClassEvent += (player, selected_class) ->
# 2. Do something with that selection
HandleClassSelection(player, selected_class)
# This is the "brain" that handles the logic
HandleClassSelection(player: Player, class_name: string): void =
# This is a simple if/else statement.
# It's like checking the storm timer: if time > 0, storm is active.
if class_name == "Hero":
# Give the player a Shotgun
# We use the 'Grant Item' device logic, but simplified for Verse
# Note: In a real setup, you might use Item Granter devices linked to this script
player.GrantWeapon(Shotgun{})
player.GrantItem(ShieldPotion{})
elif class_name == "Villain":
# Give the player a Sniper
player.GrantWeapon(SniperRifle{})
player.GrantItem(Cloak{})
else:
# Default fallback if something goes wrong
print("Player picked an unknown class. Giving them a fist.")
player.GrantWeapon(Fist{})
Walkthrough: What Just Happened?
class ClassPickerController < creative_object:: This defines a new device type. In the Scene Graph, this is a new "Entity" we created.selector_device: ClassSelectorUIDevice = ClassSelectorUIDevice{}: This is a variable (a container that changes). Think of it like a Loot Drop slot. Initially, it’s empty, but we’re telling Verse: "When the game starts, fill this slot with the Class Selector UI device I placed in the editor."OnBegin<override>(): This is an event. An event is like a Trigger. It fires when a specific condition is met (in this case, when the game begins).selector_device.SelectedClassEvent += ...: This connects the event. It’s like wiring a Switch to a Prop Mover. When the "SelectedClassEvent" fires (player clicks a button), the code inside the arrow->runs.HandleClassSelection: This is a function. A function is a Recipe. You give it ingredients (player, class_name), and it follows steps to produce a result (equipping items).
Try It Yourself
You’ve got the basics! Now, let’s make it harder.
Challenge: Add a third class called Jester. When a player selects Jester, instead of giving them weapons, make them respawn with a random color (use a Color Picker device) and give them a Party Gun.
Hint: You’ll need to:
- Add
Jesterto your Class Designer. - Add an
elif class_name == "Jester":block in your Verse code. - Use
player.Respawn()to force a respawn, andplayer.GrantWeapon(PartyGun{})to give the item.
Don’t forget to save your Verse file and reload the island in UEFN to test it!
Recap
- Classes are custom loadouts defined in the Class Designer.
- The Class Selector UI is the menu players interact with (popup or map tab).
- Verse acts as the bridge, listening for the
SelectedClassEventand executing the logic to equip the player. - The Scene Graph connects these devices, allowing the UI to talk to the gameplay logic.
Now go forth and let your players choose their fate. Or at least choose their shotgun.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-class-selector-ui-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-class-selector-ui-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-class-selector-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-class-selector-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/devices/class_selector_ui_device
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add using-class-selector-ui-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.