How to Build a Castle That Doesn’t Look Like a Spreadsheet
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.
How to Build a Castle That Doesn't Look Like a Spreadsheet
Look, we've all been there. You want to build a medieval fortress for your island, so you start placing individual walls and roofs. Ten minutes later, you have a structure that looks less like "Game of Thrones" and more like "IKEA Furniture Assembled by a Blindfolded Gnome."
Stop building bricks. Start building scenes.
In this tutorial, we're going to use Verse (Epic's programming language) to automate the placement of castle prefabs. We aren't just dropping assets; we're writing code that acts like a magical construction crew, placing walls, towers, and gates in a perfect circle around your spawn point. By the end, you'll have a functioning castle gate that opens when players get close, and you'll understand how the Scene Graph works without your head exploding.
What You'll Learn
- Prefabs vs. Props: Why you should never build a castle wall-by-wall again.
- The Scene Graph: Understanding how objects live in the world (the "Family Tree" of your island).
- Variables & Constants: Storing data like "Gate Open" or "Castle Radius."
- Functions: Creating a reusable "Build Wall" instruction.
- Events: Reacting to players entering your castle zone.
How It Works
1. The Scene Graph: It's a Family Tree
In Fortnite Creative, everything on your island is an Entity. Think of an Entity as a single object in the world—a player, a prop, a light, or a spawned prefab.
These Entities are organized in a Hierarchy (also called the Scene Graph). Imagine a family tree:
- The Island is the Grandparent.
- Folders or Groups are the Parents.
- Props (like a specific wall) are the Children.
When you move a Parent, all its Children move with it. When you delete a Parent, the Children vanish. In Verse, we interact with these Entities by their Path (their address in the family tree). If you know the path, you can change anything.
2. Prefabs: The "Loot Drop" of Building
A Prefab is a pre-built collection of Entities. Instead of placing 50 individual walls to make a tower, you place one "Castle Tower" Prefab. Under the hood, that Prefab is just a folder containing 50 smaller props, all parented together.
Using Verse, we can spawn these Prefabs dynamically. This is like calling in a supply drop, but instead of a box falling from the sky, you're commanding the universe to poof a castle wall into existence.
3. Variables: The Storm Timer of Data
A Variable is a container for information that can change. Think of it like a Storm Timer.
- At the start, the timer is set to 10 minutes.
- As time passes, the number changes.
- You can read the timer to know when to close the zone.
In Verse, we use variables to store things like:
CastleRadius: How big is our castle? (This doesn't change, so it's a Constant).GateOpen: Is the gate open or closed? (This changes based on player proximity).
4. Functions: The "Rebuild" Button
A Function is a block of code that performs a specific task. Think of it like the Rebuild button in Creative mode.
- You press the button (call the function).
- The game looks at your blueprint (the code inside the function).
- It executes the steps (deletes old props, places new ones).
We'll write a function called PlaceWall that takes a location and puts a wall there. We'll call it multiple times to build a circle.
Let's Build It
We are going to build a Castle Gate System.
- We will define a Constant for the castle radius.
- We will write a Function to spawn a "Castle Gate Tower" prefab at a specific spot.
- We will use an Event to detect when a player enters the castle, which will "open" the gate (by changing a property of the gate entity).
Note: In UEFN, you typically place a Verse Device (like a Spawner or a Scriptable Actor) and attach this code to it. For this tutorial, we assume you have a Verse Device placed in your island.
The Code
# We need access to Verse's core tools
using { /Verse.org/Simulation }
using { /Verse.org/Native }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
# This is our main script, implemented as a creative_device
# so it can be placed directly on your UEFN island.
castle_builder := class(creative_device):
# CONSTANT: The radius of our castle.
# Like setting the storm size once in the editor, this never changes.
CastleRadius : float = 1000.0
# VARIABLE: Tracks if the gate is open.
# Like a health bar, this changes during the game.
var GateIsOpen : logic = false
# Reference to a trigger device placed in the editor.
# Wire your "castle entrance" trigger_device to this in the UEFN
# outliner so the device knows which trigger to listen to.
@editable
EntranceTrigger : trigger_device = trigger_device{}
# EVENT: This runs when the island starts.
# Think of this as the "Start of Match" button.
OnBegin<override>()<suspends> : void =
# Call our function to build the castle walls
BuildCastleWalls()
# Start listening for players entering via the trigger
ListenForPlayers()
# FUNCTION: Builds a circle of castle towers.
# This is like saying "Place a wall here" repeatedly.
# Note: Runtime asset spawning from a string path is not supported in
# Verse/UEFN. Instead, wire up to eight pre-placed creative_prop
# devices (one per tower slot) in the editor and enable/teleport them
# here. The loop below shows the position math; adapt it to your
# prop references as needed.
BuildCastleWalls() : void =
# We'll place 8 towers in a circle
var Index : int = 0
loop:
if (Index >= 8):
break
# Calculate angle for this tower (0 to 360 degrees)
Angle : float = (Index * 45.0) * (PiFloat / 180.0) # Convert to radians
# Calculate X and Y position using built-in trig
X : float = CastleRadius * Cos(Angle)
Y : float = CastleRadius * Sin(Angle)
# Build a transform at the computed position (Z = 0, flat ground).
# In UEFN/Verse, X is forward, Y is right, Z is up.
TowerTransform : transform = transform{
Translation := vector3{X := X, Y := Y, Z := 0.0},
Rotation := rotation{},
Scale := vector3{X := 1.0, Y := 1.0, Z := 1.0}
}
# --- Spawn point ---
# Wire a creative_prop (set to your Castle Gate Tower asset in
# the editor) to an array called TowerProps and call:
# TowerProps[Index].TeleportTo[TowerTransform]
# That is the real UEFN pattern for placing pre-configured props
# at runtime. Direct string-based asset spawning is not available
# in Verse.
# Example (requires @editable TowerProps : []creative_prop):
# if (Prop := TowerProps[Index]):
# Prop.TeleportTo[TowerTransform]
set Index += 1
# FUNCTION: Subscribes to the entrance trigger device.
# This is like setting a tripwire at the castle gate.
ListenForPlayers() : void =
# trigger_device exposes a TriggeredEvent that fires with the
# instigating agent whenever a player walks into the trigger volume.
EntranceTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)
# EVENT HANDLER: Runs when a player enters the trigger zone.
OnPlayerEntered(InstigatingAgent : ?agent) : void =
# If the gate isn't already open...
if (GateIsOpen = false):
# Open the gate!
set GateIsOpen = true
# Cast agent to fort_character so we can use player-facing APIs.
# note: fort_character is the real runtime type for a Fortnite player.
if (ActualAgent := InstigatingAgent, Character := ActualAgent.GetFortCharacter[]):
Print("Welcome to the Castle! Gate is open.")
# In a full build you would find the gate prop here and call
# something like:
# GateProp.TeleportTo[OpenTransform]
# or trigger a cinematic_sequence_device to play an open animation.```
### Walkthrough: What Just Happened?
1. **`CastleRadius : float = 1000.0`**: We defined a constant. This is our "Storm Size." It's set once and never changes. If you want a bigger castle, you change this one number.
2. **`BuildCastleWalls()`**: This is our **Function**. It's a reusable instruction. Inside, we used a **Loop** (`loop` / `break`). A loop is like pressing the "Rebuild" button 8 times in a row, but each time we adjust the position slightly.
3. **`vector3{X := x, Y := y, Z := 0.0}`**: This creates a **Position** in the 3D world. X is forward/back, Y is left/right, Z is up/down (we kept it at 0.0 for now, assuming flat ground).
4. **`TowerTransform` / `TeleportTo`**: Because Verse cannot spawn assets from a string path at runtime, the real UEFN pattern is to pre-place `creative_prop` devices in the editor (pointed at your Castle Gate Tower asset), then move them to the calculated positions with `TeleportTo`. The code above shows exactly where and how to do that.
5. **`EntranceTrigger.TriggeredEvent.Subscribe`**: This is an **Event**. We're telling Verse: "Hey, whenever a player walks into this trigger volume, run this code." This is how you make interactive games.
## Try It Yourself
**Challenge:** Modify the `BuildCastleWalls` function to build a **square** instead of a circle.
*Hint:* Instead of using `Cos` and `Sin` (which create circles), you can place towers at the four corners. You'll need to calculate the positions manually using the `CastleRadius`. For example, one corner might be at `(CastleRadius, 0, CastleRadius)`.
*Don't forget:* You'll need to adjust the number of towers in your loop or remove the loop entirely and just place 4 towers!
## Recap
* **Prefabs** are pre-built structures. Use them instead of individual props.
* The **Scene Graph** is the hierarchy of your island. Everything is an Entity.
* **Constants** are unchangeable values (like map settings). **Variables** change (like game state).
* **Functions** are reusable blocks of code (like the Rebuild button).
* **Events** let your code react to player actions (like entering a zone).
Now go build a castle that actually looks like a castle, not a spreadsheet error.
## References
- https://dev.epicgames.com/documentation/en-us/fortnite/castle-prefabs-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-castle-prefabs-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-prefabs-and-galleries-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-prefabs-and-galleries-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/seaside-prefabs-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-castle-prefabs-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.