Build Your Own Moving Platform with Scene Graph
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 Moving Platform with Scene Graph
Imagine you are building a level in Fortnite. You want a platform that moves up and down. Usually, you would place many devices. This takes a long time. It also uses a lot of computer memory. Scene Graph helps you build faster. It lets you create smart objects. These objects have their own rules. You can copy them easily. This tutorial shows you how to make a moving platform. You will learn to use Verse components. You will also learn about entities and prefabs. By the end, you will have a playable platform. You can jump on it. It will move when you touch it. Let’s start building!
What You'll Learn
- What a Scene Graph is.
- What an Entity and a Component are.
- How to make a platform move with Verse.
- How to use a Prefab to reuse your work.
How It Works
Think of your game world like a big toy box. Inside the box are many toys. Each toy is an Entity. An entity is just an object in the world. It could be a crate, a player, or a platform.
Now, think about what each toy does. A ball rolls. A ball bounces. A button clicks. These actions are called Components. In Verse, we write code for these actions. We call this code a Verse Component.
A Prefab is like a mold. You make one perfect toy. Then you can press a button to make ten more. They all act the same. This is very fast. You do not need to code each one. You just use the mold.
We will make a "Moving Platform" prefab. It will have a script. The script will tell the platform to move up and down. When you place the prefab in your level, it works automatically. This is the power of Scene Graph. It separates the look of the object from its behavior.
Let's Build It
First, open Unreal Editor for Fortnite (UEFN). Create a new project. Choose the Blank template. Make sure Scene Graph System is enabled in settings.
Next, we need to create our script. We will make a component that moves an entity. We use a simple loop. The loop makes the platform rise and fall.
Here is the Verse code for our moving platform.
# This is our main script file.
# It defines a component for our platform.
using { /Fortnite.com/Devices }
using { /Verse.org/Sim }
# We create a new type called MovingPlatform.
# This is our "Component" definition.
MovingPlatform := class(Component):
# This is the speed of movement.
# It is a constant value.
MovementSpeed := 100.0
# This function runs every frame.
# It updates the platform's position.
OnUpdate := func(event: UpdateEvent):
# Get the current position of the entity.
current_pos := GetTransform().Location
# Calculate the new position.
# We move it up or down based on time.
new_y := current_pos.Y + (MovementSpeed * event.DeltaTime)
# Create the new transform.
new_transform := Transform{
Location: Vector{
X: current_pos.X,
Y: new_y,
Z: current_pos.Z
},
Rotation: GetTransform().Rotation
}
# Apply the new transform.
SetTransform(new_transform)
Let’s look at this code.
The line MovingPlatform := class(Component): starts our script. It says we are making a new kind of component.
The line OnUpdate := func(event: UpdateEvent): is very important. This function runs many times per second. It is like a heartbeat. Every time the heart beats, we check where the platform is.
We get the current position. Then we add to the Y value. The Y value is up and down. We add MovementSpeed times DeltaTime. DeltaTime is the time since the last frame. This makes the movement smooth.
Finally, we call SetTransform. This moves the entity in the world.
Now, go back to UEFN. Create a simple box. This is your platform. Right-click it. Select Create Prefab. Name it "MovingPlatform".
In the details panel, find the Verse Component section. Add your script. Attach it to the box.
Now, drag the prefab into your level. You can place it anywhere. It will move up and down. You can copy it again. You can make a whole level of moving platforms.
Try It Yourself
You have a platform that moves. But it moves forever. It goes up and down without stopping. This can be boring.
Challenge: Make the platform move up, then down, then up again. It should stay in one area.
Hint: You need to check the position. If it goes too high, change the direction. If it goes too low, change the direction again. You can use a simple if statement.
Recap
Scene Graph makes level creation fast. Entities are objects. Components are behaviors. Prefabs are reusable molds. You wrote a Verse component to move a platform. You placed it in your level. Now you can build bigger games. Keep experimenting. Have fun coding!
References
- https://dev.epicgames.com/documentation/en-us/fortnite/create-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/create-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/34-20-fortnite-ecosystem-updates-and-release-notes
- https://dev.epicgames.com/documentation/en-us/fortnite/getting-started-in-scene-graph-in-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/creating-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite
Verse source files
- 01-standalone.verse · standalone
Turn this into a guided course
Add creating-a-platformer-with-scene-graph-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
- create-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite ↗
- create-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite ↗
- Updated Scene Graph Platformer Tutorial ↗
- getting-started-in-scene-graph-in-fortnite ↗
- creating-a-platformer-with-scene-graph-in-unreal-editor-for-fortnite ↗
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.