Keep Them in the Driver’s Seat!
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
Keep Them in the Driver's Seat!
Have you ever been in a car game, only to jump out and walk away? That can be boring for everyone. Let's make a rule: No getting off the ride!
In this tutorial, we will use Verse to lock players into their vehicles. We will build a system that checks if a player tries to leave. If they do, the game will gently push them back in. It's like an invisible seatbelt!
What You'll Learn
- How to listen for a Player Exit event.
- How to find the Vehicle a player was just sitting in.
- How to use the Assign Driver command to keep players on board.
- How to use Scene Graph tools to connect these actions.
How It Works
Imagine you are playing a racing game. You jump into your car. You drive fast. Then, you decide to jump out.
In a normal game, you just walk away. But in our game, we want to stop that. We need a "guard" that watches the player.
Here is the plan:
- Watch for the Exit: We tell the game to listen for the moment a player tries to leave a vehicle. This is called an Event. An event is like a doorbell. When the player exits, the doorbell rings.
- Find the Car: When the doorbell rings, we need to know which car they were in. The game remembers this for us.
- Send Them Back: We use a special command called Assign Driver. This command says, "Hey, you! Get back in that car right now!"
We will use a Device to do this work. A device is a tool in UEFN that has logic attached to it. We will write a small script inside this device.
Let's Build It
We will create a simple device that locks players into any vehicle they enter.
Step 1: Add the Device
- Open your Fortnite Creative island.
- Go to the Devices tab.
- Search for Empty. Add an Empty device to your map. It doesn't matter where you put it. You can hide it in a corner.
- Select the Empty device.
- Click Edit Verse to open the code editor.
Step 2: Write the Code
Copy this code into your editor. Read the comments to understand what each part does.
# This is our main device script.
# It runs when the game starts.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Vehicles }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# We create a new device called lock_driver_device.
# This device will hold our logic.
lock_driver_device := class(creative_device):
# This function runs when the game begins.
OnBegin<override>()<suspends> : void =
# We get all players currently in the game session.
# GetPlayspace gives us access to the current game space.
Playspace := GetPlayspace()
# We loop over every player and subscribe to their
# ExitedVehicleEvent. This is like giving each player
# their own doorbell.
for (Player : Playspace.GetPlayers()):
# Cast the player to a fort_player so we can
# access vehicle-related events.
if (FortPlayer := player_is_fort_character[Player]):
# Subscribe runs our handler every time
# this player exits a vehicle.
FortPlayer.ExitedVehicleEvent.Subscribe(OnPlayerExitedVehicle)
# This handler is called every time a subscribed player exits a vehicle.
# 'Result' carries info about which vehicle was exited.
OnPlayerExitedVehicle(Result : exit_vehicle_result) : void =
# Grab the vehicle the player just left.
Vehicle := Result.Vehicle
# Grab the player (fort_character) who jumped out.
Character := Result.Character
# Here is the magic!
# We assign the player back to the vehicle as its driver.
# This forces them to get back in.
# note: SetDriver is the real API on fort_vehicle in UEFN Verse.
Vehicle.SetDriver(Character)
# Optional: You could print a message to the console.
# Print("A player tried to exit — sending them back!")
Step 3: Understand the Code
class(creative_device): This defines our device. It is a container for our code.OnBegin: This function runs once when the game starts. It sets up our "camera" (the event listener).ExitedVehicleEvent: This is the doorbell. It rings every time that player exits a vehicle.Result.Character: This grabs the player character who jumped out.Result.Vehicle: This grabs the car they were just in.Vehicle.SetDriver(Character): This is the seatbelt. It puts the player back in the driver's seat.
Step 4: Test It
- Save your code.
- Play your island.
- Get into a car (like a Driftboard or a Car).
- Try to jump out.
- Watch what happens! The player will instantly snap back into the driver's seat.
Try It Yourself
Great job! You made a lock-on system. Now, let's make it more fun.
Challenge: Instead of forcing the player back in immediately, let's give them a choice. Modify the code to print a message to the console when a player tries to exit.
Hint:
You can use the Print function to show text. Try adding this line inside the if statement:
Print("Oh no! You can't leave!")
Can you make the message say the player's name? Look at the player variable we saved earlier.
Recap
- We used an Event to listen for players exiting vehicles.
- We used Result.Character and Result.Vehicle to find out who left and what they left.
- We used SetDriver to keep players in their cars.
- This makes racing games more exciting because no one can quit early!
References
- https://dev.epicgames.com/documentation/en-us/fortnite/design-a-car-racing-game-in-fortnite-creative
- 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/fortnite-creative/create-a-hoverboard-race-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-hoverboard-race-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/uefn/pizza-pursuit-6-final-result-in-verse
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Exit the Vehicle 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.