Car Racing 4: How to Build a Scoring System That Doesn't Suck
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.
Car Racing 4: How to Build a Scoring System That Doesn't Suck
So you’ve got a track. You’ve got cars. You’ve got players crashing into walls at 80mph like it’s their job. But right now, your race is just… chaos. Who won? Did anyone actually finish? Or did everyone just drive in circles until the server crashed?
In this tutorial, we’re fixing that. We’re going to build a Scoring System. Think of this as the game’s "brain" that keeps track of who crossed the finish line first, second, and third. No more arguing about who crossed the line first. The code doesn’t lie.
We aren’t writing complex algorithms here. We’re connecting devices like LEGO bricks. If you can build a house, you can build a winner.
What You'll Learn
- The Scene Graph: How devices talk to each other (the "hierarchy" of your game).
- Variables vs. Constants: The difference between things that change (your score) and things that stay the same (the rules).
- Events: How a checkpoint "shouts" to the rest of the game when someone passes it.
- The Score Manager: The device that actually holds the numbers and declares the winner.
How It Works
Before we touch a single line of code, let’s understand the logic using Fortnite mechanics you already know.
1. The Scene Graph (Your Game’s Family Tree)
In programming, the Scene Graph is just a fancy way of saying "where everything lives and how they’re connected." Imagine your Fortnite island is a family.
- The Race Manager is the parent. It controls the start/stop of the race.
- The Checkpoints are the kids. They do specific tasks (detecting players).
- The Score Manager is the referee. It listens to the kids and keeps the score.
In UEFN (Unreal Editor for Fortnite), everything is an Entity. An Entity is just an object in your world (a car, a wall, a checkpoint). Devices are the "brains" attached to those entities.
2. Variables (The Changing Stuff)
A Variable is a box that holds a value that can change.
- Game Analogy: Your HP (Health Points). It starts at 100, but when you get shot, it changes to 95, then 50, then 0.
- In our Race: The Leaderboard is a variable. It changes every time someone crosses a checkpoint.
3. Constants (The Fixed Stuff)
A Constant is a value set once and never changed.
- Game Analogy: The Storm Damage per zone. You set it in the editor, and the game uses that number forever.
- In our Race: The Checkpoint ID. Checkpoint 1 is always ID 1. It doesn’t become ID 5 just because you moved it.
4. Events (The Trigger)
An Event is something that happens that tells the code to "do something."
- Game Analogy: The Battle Bus opening its doors. That’s an event. It triggers players to jump.
- In our Race: A player crossing a Race Checkpoint. That event triggers the Score Manager to update the time.
Let's Build It
We are going to set up a simple system where:
- A player crosses Checkpoint 1.
- The system records that they are "in the race."
- They cross the Finish Line (Checkpoint 2).
- The Score Manager updates their rank.
The Setup (No Code Yet)
You need these devices in your level:
- Race Manager: Place this near the start. This controls the race state (Started, Ended).
- Two Race Checkpoints: Place one at the start line and one at the finish line.
- Score Manager: Place this anywhere (it doesn’t move). This is the brain.
The Code
In UEFN, we use Verse to make these devices talk to each other. Don’t panic. This code is just a set of instructions.
Copy this into a new Verse Script component attached to your Score Manager (or a global script, depending on your setup, but for beginners, attaching it to the manager is easiest).
# This is a comment. The game ignores lines starting with #.
# 1. IMPORTS: Bringing in the tools we need.
# Think of this as opening your toolbox.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
# 2. THE CLASS: This is our "Blueprint" for the Score Manager.
# It’s like the rulebook for how this specific manager behaves.
score_manager_device := class(creative_device):
# 3. VARIABLES (The Changing Stuff)
# 'leaderboard' is a list that stores players and their times.
# It starts empty, like a blank scoreboard.
leaderboard: list<player_score> = []
# 'race_active' is a boolean (true/false).
# It’s like the storm timer: is the storm on? Yes/No.
race_active: bool = false
# 4. DEVICE REFERENCES (The Connections)
# We need to tell this script which Checkpoints to listen to.
# 'start_checkpoint' and 'finish_checkpoint' are placeholders.
# You will drag-and-drop your actual devices here in the editor.
start_checkpoint: race_checkpoint_device = create()
finish_checkpoint: race_checkpoint_device = create()
race_manager: race_manager_device = create()
# 5. FUNCTIONS (The Actions)
# 'OnBegin' runs once when the game starts.
# Like the "Loadout" screen before you drop in.
override OnBegin() <server, transformable>:
super.OnBegin()
# Set the race to inactive initially
race_active = false
# Clear any old scores
leaderboard = []
# 'OnPlayerCrossedStart' is an EVENT.
# It fires when a player hits the START checkpoint.
OnPlayerCrossedStart(player: player, checkpoint: race_checkpoint_device) <server>:
if race_active == false:
# Start the race if it hasn't started
race_manager.Start()
race_active = true
# Tell everyone the race is on
Print("Race Started!")
# 'OnPlayerCrossedFinish' is the MAIN EVENT.
# This is what happens when someone crosses the finish line.
OnPlayerCrossedFinish(player: player, checkpoint: race_checkpoint_device) <server>:
# Only do this if the race is actually going
if race_active == true:
# Get the player's current time from the race manager
# (This is a simplified concept; real Verse needs more setup)
# For this tutorial, we just record the finish.
# Add this player to our 'leaderboard' variable
# Think of this like adding a name to the 'Elimination List'
new_score := player_score(PlayerId = player.GetPlayerId(), FinishTime = 0)
leaderboard = Append(leaderboard, new_score)
# Sort the list (Who finished first?)
# This is like the 'Squads' tab sorting by eliminations
leaderboard = SortBy(leaderboard, FinishTime)
# Announce the winner
winner := leaderboard[0] # The first person in the sorted list
Print("Winner is Player: ", winner.PlayerId)
Walkthrough: What Just Happened?
- Imports: We told Verse, "Hey, I need to use Fortnite devices."
- Class: We created a
score_manager_device. This is the container for all our logic. - Variables: We made a
leaderboardlist. In Fortnite, a list is like your Inventory. It can hold multiple items (players). We also maderace_activea boolean. It’s eithertrue(race on) orfalse(race off). - OnBegin: When the game loads, we reset everything. Like hitting "Restart" in a lobby.
- Events (
OnPlayerCrossedStart/OnPlayerCrossedFinish): These are the magic parts. You don’t "call" these functions manually. They automatically run when a player crosses the specific checkpoint you linked in the editor.- Note: In the real UEFN editor, you drag the actual Checkpoint devices from your scene into the
start_checkpointandfinish_checkpointslots in the script’s properties panel. The code above shows the structure of how they interact.
- Note: In the real UEFN editor, you drag the actual Checkpoint devices from your scene into the
Try It Yourself
You’ve got the basics. Now, make it fun.
Challenge: Add a "Penalty System." If a player crosses a Red Checkpoint (a wrong turn), their time should increase by 5 seconds.
Hint:
- Add a third
Race Checkpointdevice. - In the code, create a new event:
OnPlayerCrossedRedCheckpoint. - Inside that event, find the player’s score in the
leaderboardand add 5 to their time. - Remember: You need to sort the
leaderboardagain after adding the penalty, or the winner might be wrong!
Don’t overthink the math. Just think: Player hits Red Checkpoint -> Add 5 seconds -> Re-sort list.
Recap
- Scene Graph: Your game’s hierarchy. Devices are entities with brains.
- Variables: Boxes that change (like HP or a Leaderboard).
- Constants: Fixed rules (like Checkpoint IDs).
- Events: Triggers that happen automatically (like crossing a checkpoint).
- Score Manager: The device that holds the logic and declares the winner.
You now have the tools to build a race that actually has a winner. Go make some chaos. And remember: if the code breaks, check your connections. 90% of bugs are just loose wires.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/car-racing-4-add-a-scoring-system-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/car-racing-3-add-vehicles-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/car-racing-4-add-scoring-system-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/car-racing-3-add-vehicles-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/build-a-carracing-game-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add car-racing-4-add-a-scoring-system-in-unreal-editor-for-fortnite 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.