Build Your Own Rocket Racing Garage!
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.
Build Your Own Rocket Racing Garage!
Do you love driving fast cars in Fortnite? Now you can build your own racing island! You will learn how to place a special device that creates a cool sports car. When players touch a button, a car will appear for them to drive. It is like magic, but it is actually programming!
What You'll Learn
- What a Sports Car Spawner is.
- How to place it in your world.
- How to make a car appear when a player touches a button.
- How to let players pick their favorite car color.
How It Works
Imagine you are at a toy store. You have a machine that can print any toy car you want. You just need to push the right button. In Fortnite Creative, the Sports Car Spawner is that machine. It sits on the ground. It waits for a signal. When it gets the signal, it makes a car appear right where it is standing.
This is very useful for racing games. You can put spawners at the starting line. When the race starts, all the cars appear at once. Then players can drive away.
Here is the cool part. Players can choose their own car look. If a player has a shiny red car in their locker, their spawned car will be red. If they have a blue one, it will be blue. The spawner uses the player's personal choices. This makes every player feel special.
We will use a simple trick to make the car appear. We will use a Trigger. A trigger is like a pressure plate. When a player steps on it, it sends a message. The message tells the spawner, "Hey! Make a car now!"
Let's Build It
We will build a small garage. You will place a spawner. You will place a trigger. Then you will connect them. Here is the code to make it work.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our main script.
# It controls the garage.
MyGarageDevice := class(creative_device):
# This is the spawner.
# It will make the car appear.
# note: Assign this device reference in the UEFN details panel after adding the Verse device to your island.
@editable
car_spawner : vehicle_spawner_sports_car_device = vehicle_spawner_sports_car_device{}
# This is the trigger.
# It detects when a player steps on it.
# note: Assign this device reference in the UEFN details panel after adding the Verse device to your island.
@editable
start_button : trigger_device = trigger_device{}
# This function runs when the game starts.
OnBegin<override>()<suspends> : void =
# We listen for the button press.
# When the button is pressed, we call "OnButtonPressed".
start_button.TriggeredEvent.Subscribe(OnButtonPressed)
# This function makes the car appear.
OnButtonPressed(agent : agent) : void =
# We check that the agent is a player before spawning.
if (player := player[agent]):
# This line tells the spawner to spawn a car.
# It uses the player's chosen car skin.
car_spawner.SpawnVehicleFor(player)```
### Walkthrough
1. **The Setup**: We create a class called `MyGarageDevice`. This is like a blueprint. It tells the computer what our garage device can do.
2. **The Devices**: We name two things. `car_spawner` is the device that makes the car. `start_button` is the trigger you step on. We give them names so we can find them later.
3. **Listening**: In `OnBegin`, we tell the `start_button` to watch for players. If a player enters the button, it calls `OnButtonPressed`.
4. **The Magic**: In `OnButtonPressed`, we call `car_spawner.SpawnVehicleFor(player)`. This is the important line. It tells the spawner to create a car for that specific player. The player's locker settings will be used automatically.
### How to Place It in UEFN
You do not need to write code from scratch. You can use devices directly.
1. Open your island in UEFN.
2. Find the **Sports Car Spawner** in the device menu. Place it on the ground. Name it "CarSpawner".
3. Find the **Trigger** device. Place it next to the spawner. Name it "StartButton".
4. Add a **Verse Script** device to your island.
5. Paste the code above into the script.
6. Select your Verse device in UEFN. In the **Details** panel, assign `car_spawner` to your Sports Car Spawner and `start_button` to your Trigger using the `@editable` slots.
7. Playtest! Step on the button. A car should appear!
## Try It Yourself
Can you make two cars appear? Try placing two Sports Car Spawners. Name them "Car1" and "Car2". Update the code to have two spawner variables. Then, when the player steps on the button, make both cars spawn.
**Hint:** You will need to call `SpawnVehicleFor` twice. Once for each spawner.
## Recap
You built a working car garage! You learned that a Sports Car Spawner creates vehicles. You learned that triggers can start actions. You learned that players can choose their own car colors. Great job, coder! You are ready to build a full racing track next.
## References
* https://dev.epicgames.com/documentation/en-us/fortnite/using-sports-car-spawner-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/design-a-speedway-race-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/designing-a-speedway-race-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-sedan-spawner-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-sports-car-spawner-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.