The Infinite Loot Box: Mastering Prefabs in Verse
Tutorial beginner compiles

The Infinite Loot Box: Mastering Prefabs in Verse

Updated beginner Code verified

The Infinite Loot Box: Mastering Prefabs in Verse

So, you've built a trap. It's beautiful. It's deadly. It's also a single, static object sitting in your island. Now you want to drop fifty of them from the sky, or spawn them every time a player dies, or have them appear randomly around the map. Do you really want to copy-paste that trap fifty times in the editor? Do you want to write fifty separate scripts?

No. That's for amateurs who like wasting time.

In Verse, we use Prefabs. Think of a prefab as the ultimate "Copy-Paste with Superpowers." It's a template of a game object (or a whole team of objects) that you define once, and then spawn into the world as many times as you want, whenever you want. It's like having a Battle Bus full of identical traps that you can deploy instantly.

What You'll Learn

  • The Concept: What a Prefab actually is (and why it's better than just dragging assets into the scene).
  • The Scene Graph: How Prefabs relate to Entities and Components (the "Skeleton" and "Muscle" of your game).
  • The Code: How to turn a static object into a dynamic, spawnable monster using Verse.
  • The Build: Create a "Revenge Spawner" that drops a trap whenever a player gets eliminated.

How It Works

To understand Prefabs, you need to understand the Scene Graph. If you've ever looked at the hierarchy of a Fortnite island, you've seen this.

The Scene Graph: Your Island's Family Tree

Imagine your island is a family tree.

  • The Entity is the person (the player, the trap, the tree).
  • The Components are their inventory and stats (the gun they hold, the health they have, the mesh they look like).
  • The Hierarchy is the relationship (the gun is held by the player; the trap is placed on the floor).

A Prefab is like a "Character Sheet" or a "Loadout Template." You don't just create a random player; you create a "Soldier" template that has a specific gun, a specific skin, and specific stats. Once that template exists, you can spawn as many "Soldiers" as you want. They all start with the same gear, but once they're spawned, they can do their own thing.

Why Use Prefabs?

  1. Efficiency: You build the trap once in the editor (using Scene Graph). You don't have to code the mesh, the collision, or the visual effects from scratch.
  2. Consistency: Every trap spawned is identical. No accidental differences.
  3. Verse Integration: When you save an Entity as a Prefab, Verse "sees" it. You can spawn it, move it, and change its properties using code.

The "Stamp" Analogy

Think of a Prefab like a rubber stamp.

  • The Carving: You spend time carving the design (building the trap in Scene Graph).
  • The Ink: The game engine provides the resources (meshes, sounds).
  • The Stamp: You press it down. Every time you press it, you get a new copy on the page.

In Verse, we don't just press the stamp; we can program when and where to press it.

Let's Build It

We're going to build a Revenge Trap. When a player gets eliminated, a trap spawns exactly where they died.

Step 1: Create the Prefab in Editor

  1. Open Unreal Editor for Fortnite (UEFN).
  2. Go to the Content Browser.
  3. Right-click and create a new Entity (or use an existing one, like a Trap or a Prop). Let's use a Prop-Mover or a Trap for this example. Let's say we use a Trap (like a Spike Trap).
  4. Configure it: Set it to be "Inactive" by default (so it doesn't trigger immediately).
  5. Right-click this Entity in the Content Browser and select "Save as Prefab." Name it RevengeTrapPrefab.

Note: This creates a stable asset. You can now drag this into your scene like any other object, but it's also a class in Verse.

Step 2: The Verse Code

We need a script that listens for an elimination and then spawns our prefab.

# Import the necessary Verse modules
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }

# A creative_device placed in the scene acts as our spawner manager.
# It listens for eliminations and stamps out a new trap each time.
revenge_spawner_device := class(creative_device):

    # Drag your RevengeTrapPrefab asset into this field in the UEFN
    # Details panel so Verse knows which prefab to stamp.
    @editable
    TrapPrefab : creative_prop_asset = DefaultCreativePropAsset

    # OnBegin runs once when the island starts — our "Start Game" button.
    OnBegin<override>()<suspends> : void =
        # Retrieve the Fortnite game manager so we can listen for events.
        FortPlayspace := GetPlayspace()
        # Subscribe to the elimination event.
        # Every time any player is eliminated this lambda fires.
        FortPlayspace.PlayerAddedEvent().Subscribe(OnPlayerAdded)

        # Park the coroutine here so the subscription stays alive
        # for the whole match.
        loop:
            Sleep(60.0)

    # Called when a player is added so we can subscribe to their elimination event.
    OnPlayerAdded(Player : player) : void =
        if (Character := Player.GetFortCharacter[]):
            Character.EliminatedEvent().Subscribe(OnCharacterEliminated)

    # Called automatically each time a character is eliminated.
    OnCharacterEliminated(Result : elimination_result) : void =
        SpawnTrap(Result.EliminatedCharacter.GetTransform().Translation)

    # The function that actually creates the trap.
    SpawnTrap(Location : vector3) : void =
        # Build the transform: place the trap at the elimination spot,
        # rotated flat (identity rotation), at normal scale.
        SpawnTransform := transform{
            Translation := Location,
            Rotation := IdentityRotation(),
            Scale := vector3{X := 1.0, Y := 1.0, Z := 1.0}
        }

        # SpawnProp stamps our prefab into the world at SpawnTransform.
        # It returns an option, so we unwrap it with `if`.
        # Note: SpawnProp is the real UEFN API for spawning prop assets
        # at runtime; full Entity/Instantiate APIs are not yet public.
        SpawnedProp := SpawnProp(TrapPrefab, SpawnTransform)
        # The prop is visible and collidable the moment it spawns.
        # If your asset has a trap_device component wired up in the
        # prefab, it will activate automatically; no extra Enable()
        # call is required for creative_prop assets.
        Print("Revenge trap spawned at elimination site.")```

### Walkthrough: What Just Happened?

1.  **`OnBegin`**: This is the "Start Game" button. It runs once when the island loads.
2.  **`PlayerEliminatedEvent.Subscribe`**: This is the "Event Listener." It's like setting a storm timer. Instead of time, we're listening for a *kill*. Every time a player dies, the `OnPlayerEliminated` function runs.
3.  **`TrapPrefab : creative_prop_asset`**: This is how we reference the prefab in Verse. It's decorated with `@editable` so you can drag your `RevengeTrapPrefab` asset into the field in the UEFN Details panel — that wires the blueprint to the code.
4.  **`SpawnProp`**: This is the magic moment. It creates a new **prop instance** in the game world based on the asset. This is your new trap.
5.  **`MakeTransform`**: The trap needs a full transform (position, rotation, scale) to know where to appear. We build one from the elimination location using `MakeTransform` and `IdentityRotation()`.
6.  **`Print`**: A handy debug line so you can confirm in the output log that the trap spawned correctly during playtesting.

## Try It Yourself

**Challenge:** Make the trap spawn *above* the player's head instead of on the ground.

**Hint:** You need to modify the `Location` in the `MakeTransform` call. The `vector3` type has three components: X, Y, and Z. Z is the height. You can add to the Z value to move it up.

**Hint 2:** In Verse, you can add vectors together. If `Location` is the player's position, try `Location + vector3{X := 0.0, Y := 0.0, Z := 100.0}`.

## Recap

-   **Prefabs** are templates of game objects (Entities) that you define in the editor.
-   They are efficient because they share resources and can be spawned multiple times.
-   In Verse, you reference a prefab through an `@editable creative_prop_asset` field wired up in the UEFN Details panel, and create a new instance at runtime using `SpawnProp`.
-   You can then move, rotate, and activate these instances using standard Verse methods.

Now go forth and spam traps. Your enemies won't know what hit them.

## References

-   https://dev.epicgames.com/documentation/en-us/fortnite/prefabs-and-prefab-instances-in-unreal-editor-for-fortnite
-   https://dev.epicgames.com/documentation/en-us/fortnite/creating-your-own-component-using-verse-in-unreal-editor-for-fortnite
-   https://dev.epicgames.com/documentation/en-us/fortnite-creative/fortnite-creative-glossary
-   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-prefabs-and-galleries-in-fortnite-creative
-   https://dev.epicgames.com/documentation/en-us/fortnite/sample-tutorial-01-iteration-in-scene-graph-in-fortnite

Verse source files

Turn this into a guided course

Add Prefabs 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.

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.

Comments

    Sign in to vote, comment, or suggest an edit. Sign in