Build Your First Scene Graph Robot in Fortnite
Build Your First Scene Graph Robot in Fortnite
Welcome, future game designer! Today, we are going to learn how to build things from scratch using Verse. You know how you can drag a chair into your Fortnite island? That is easy. But what if you want to create a robot that appears only when you press a button? Or a tree that grows when you water it?
That is where the Scene Graph comes in. It is like a magical toolbox. It lets you build complex objects by snapping simple pieces together. By the end of this tutorial, you will have a small robot on your island. It will pop into existence when you click a button. You will be coding real game objects!
What You'll Learn
- What an Entity is (the body of your object).
- What a Component is (the superpowers of your object).
- How to link them together in the Scene Graph.
- How to spawn a new object using Verse code.
How It Works
Imagine you are building a Lego robot. You have a body, arms, and legs. In Fortnite, we call the whole robot an Entity. An entity is just a container. It holds everything together.
But a container is boring on its own. You need to add parts to it. These parts are called Components. Think of components as Lego bricks you snap onto your entity.
- A Mesh Component is like the plastic shell. It gives the entity a shape you can see.
- A Transform Component is like the position on the floor. It tells the entity where it sits in the world.
The Scene Graph is the big tree that holds all your entities. There is one main trunk called the Simulation Entity. Every object in your game hangs from this trunk. If you want your robot to appear, you must hang it from this trunk.
We will build a simple "Hello Bot." It will have a box shape (mesh) and a position (transform). When you click a button, our Verse code will build this robot and hang it from the trunk.
Let's Build It
We need to write a Verse script. This script will define what our robot looks like. Then, we will connect it to a button in the editor.
Here is the code. Copy this into a new Verse file in your project.
# We define a new type of object called "HelloBot"
HelloBot: entity = entity{
# We add a mesh component to give it a shape
MeshComponent: mesh_component = mesh_component{
# This sets the shape to a simple box
Mesh := StaticMesh'Engine/BasicShapes/Box.StaticMesh'
},
# We add a transform component to set its position
TransformComponent: transform_component = transform_component{
# This moves it slightly to the right so you can see it
Translation := vector3{
Left := 100.0,
Up := 50.0,
Forward := 0.0
}
}
}
# This function runs when the game starts
OnBegin<override>()<suspends>: void = (
# We find the main trunk of our scene graph
if (SimEntity := Entity.GetSimulationEntity[]):
# We add our new HelloBot to the trunk
# This makes it appear in the game!
SimEntity.AddEntities(array{HelloBot})
)
Walkthrough: What Does This Do?
HelloBot: entity = entity{...}: We are creating a blueprint. Think of this like drawing a plan for a house. We haven't built the house yet. We are just listing what it needs.MeshComponent: Inside our blueprint, we say, "This entity needs a shape." We pick a box from the engine. Now our entity has a visible body.TransformComponent: Inside our blueprint, we say, "This entity needs a location." We set theTranslation. This is like giving it GPS coordinates. We move it up (Up := 50.0) so it floats slightly above the ground.OnBegin: This is a special function. It runs once when your island starts playing.Entity.GetSimulationEntity[]: This finds the big trunk of the Scene Graph. It is the root of everything.AddEntities: This is the magic spell. It takes ourHelloBotblueprint and puts it into the real game world.
Try It Yourself
You have built the code! Now let's make it appear.
- Open your Fortnite island editor.
- Place a Trigger Volume or a Button in your world.
- Open the Verse Editor for that device.
- Paste the code above into the editor.
- Save and Publish your island.
- Play your island.
Did your robot appear? If you see a floating box, you did it! You just used the Scene Graph to create a new object from code.
Challenge: Try changing the numbers in Translation. What happens if you change Up := 50.0 to Up := 200.0? Try changing the Left value. See how the robot moves!
Recap
- Entities are containers for your game objects.
- Components are the parts you add to entities, like shapes or positions.
- The Scene Graph is the tree structure that holds all entities.
- You must add your new entities to the Simulation Entity to make them appear in the game.
You are now officially a Scene Graph creator! Keep experimenting. What other shapes can you build?
References
- https://dev.epicgames.com/documentation/en-us/fortnite/sample-tutorial-01-iteration-in-scene-graph-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/custom-inventory-and-items-overview-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/getting-started-in-scene-graph-in-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/versedotorg/scenegraph/entity
- https://dev.epicgames.com/documentation/en-us/fortnite/transforms-in-scene-graph-in-unreal-editor-for-fortnite
Verse source files
- 01-fragment.verse · fragment
Turn this into a guided course
Add Understanding the scene graph: entities and components in Verse 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.