From Bus to Battle: Setting Up Your Players in Verse
From Bus to Battle: Setting Up Your Players in Verse
So, you’ve built your island. You’ve placed your traps, your loot, and maybe even a few chaos buttons. But right now, your players are just floating in the void, or worse, spawning in the wrong spot with no gear. It’s like sending players out of the Battle Bus with a single pebble in their inventory. Not exactly the thrill of a Victory Royale, is it?
In this tutorial, we’re going to fix that. We’re going to write Verse code that acts like the Game Master, taking each player as they join, assigning them a specific starting spot, giving them their loadout, and dropping the barrier so the chaos can begin. No more wandering aimlessly. It’s time to get your squad properly deployed.
What You'll Learn
- The
playerType: Understanding how Verse identifies the people actually playing your game. - Arrays (Lists): How to manage a whole squad of players at once, rather than writing code for just one.
- The
forLoop: Automating tasks for every single player so you don’t have to manually code for Player 1, Player 2, Player 3, etc. - Device Management: Using Verse to turn on/off game devices (like barriers or vehicles) based on who is playing.
How It Works
Imagine you’re setting up a race. You have a grid of starting positions. You also have a list of drivers (players). If you have 4 drivers and 4 starting spots, you don’t want to write four separate instructions. You want one instruction that says, "For every driver, put them in their assigned spot and drop the gate."
In programming, this is called iteration. Instead of doing something once, you do it for every item in a list.
Here is the core concept we are building:
- Get the Players: Verse has a built-in list of everyone currently in the game. We call this the
playerarray. - Match Them Up: We have a list of "Starting Positions" (which might contain a car, a barrier, or a spawn point). We match each player to a specific position.
- Activate the Setup: We tell the game devices (like barriers keeping players in the lobby or cars waiting for them) to wake up and become active.
Think of it like the Lobby Timer. Before the match starts, everyone is in a safe zone. Verse checks: "Who is here? Oh, Alex and Sam. Okay, Alex, here is your car. Sam, here is your car. Now, drop the barriers."
Let's Build It
We are going to write a function called SetupStartingPositions. This function will take the list of players, find their matching starting spots, and enable the devices associated with those spots.
The Verse Code
# This is a function. Think of it as a custom command you can give the game.
# It takes one input: Players, which is a list (array) of player objects.
# <suspends> means this code might pause to wait for things to load (like cars spawning).
SetupStartingPositions(Players:[]player)<suspends>:void=
# 'Index' is the number (0, 1, 2...) and 'Player' is the actual person.
# We loop through every player in the list.
for:
Index -> Player : Players
# Here, we grab the Starting Position that matches this player's index.
# If Player is the 1st in line, we get the 1st Starting Position.
StartingPosition := StartingPositions[Index]
# We grab the specific devices attached to this starting position.
# These are references to devices you place in the UEFN editor.
Vehicle := StartingPosition.Car
Barrier := StartingPosition.Barrier
# The 'do' block runs for every player in the loop.
do:
# Enable the vehicle so the player can drive it.
# This is like flipping a switch to turn on the engine.
Vehicle.Enable()
# Enable the barrier.
# In a race, this might be the gate dropping. In a lobby,
# this might be the wall keeping them in the spawn room.
Barrier.Enable()
Walkthrough: What Just Happened?
Players:[]player: This is our input. In UEFN,[]means "Array" or "List." So[]playeris a list of players. When you call this function, you pass it the list of everyone in the game.for: Index -> Player : Players: This is the loop. It’s like the Elimination Counter. Instead of counting manually, the game automatically goes through every player.Indexis just the number (0 for the first player, 1 for the second), andPlayeris the actual human being.StartingPositions[Index]: This is how we connect the player to their spot. If Player 0 is the first person to join, we look at Starting Position 0. If Player 1 is the second, we look at Starting Position 1. It’s a perfect match.Vehicle.Enable(): Devices in UEFN (like Prop Movers, Item Granters, or Vehicle Spawners) have anEnable()command. It’s like waking up a sleeping guard. Before this, the device exists but does nothing. After this, it’s active and ready to work.
Setting It Up in UEFN
Code is useless if it doesn't know what StartingPositions is. Here is how you set this up in the editor:
- Create a Script Device: Place a Verse Script device in your level.
- Define
StartingPositions: In the device’s properties, you need a variable calledStartingPositions. It should be an Array of Actor References. - Link Your Spots: In the editor, drag and drop your starting position actors (the ones containing your cars/barriers) into that
StartingPositionsarray. Make sure the order matches how you want players to spawn. - Call the Function: In the
On Begin Playevent of your script, callSetupStartingPositionsand pass it the list of players. You can get the list of players usingGetPlayers().
Try It Yourself
You’ve got the basics, but let’s make it trickier. Right now, everyone gets the same type of car (assuming all your starting positions have the same car setup).
Challenge: Modify the SetupStartingPositions function so that it only enables the devices if the Vehicle device actually exists. If a starting position doesn't have a car assigned to it (maybe it’s a foot-race spot), the code shouldn’t crash trying to enable a null vehicle.
Hint: Look up how to check if a variable is valid or not in Verse. It’s similar to checking if a loot box actually has items in it before trying to open it.
Recap
Setting up players is the first step to any serious game mode. By using arrays to hold your players and loops to iterate through them, you can set up complex spawning systems with just a few lines of code. You learned how to match players to specific starting positions and activate the devices that make those positions work. Now, go make sure your players aren’t just floating in the void!
References
- https://dev.epicgames.com/documentation/en-us/fortnite/speedway-race-with-verse-persistence-template
- https://dev.epicgames.com/documentation/en-us/uefn/speedway-race-with-verse-persistence-template
- https://dev.epicgames.com/documentation/en-us/uefn/verse-prop-hunt-template-5-game-loop-and-round-management-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/pizza-pursuit-6-final-result-for-time-trial-in-verse
- https://dev.epicgames.com/documentation/en-us/uefn/speedway-race-with-verse-persistence-in-unreal-editor-for-fortnite
Get the complete code — free
You've read the full walkthrough. The complete, copy-paste-ready Verse solution is free for members — sign in to unlock it.
Free with your BrainDead.TV / BrainDeadGuild Discord account. The walkthrough above is always free.
Verse source files
- 01-fragment.verse · fragment
- 02-fragment.verse · fragment
Turn this into a guided course
Add Set Up the Player 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
- Enable each starting position that has a valid player with the appropriate devices. ↗
- Enable each starting position that has a valid player with the appropriate devices. ↗
- 5. Game Loop and Round Management ↗
- end up in the same selection pool. ↗
- The amount of time to wait in the pregame lobby. ↗
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.