Build a Random Dungeon with Verse
Tutorial beginner compiles

Build a Random Dungeon with Verse

Updated beginner Code verified

Build a Random Dungeon with Verse

Imagine building a Fortnite island where every time you play, the maze looks different. The walls move. The enemies hide in new spots. This is called "procedural generation." It makes your game feel fresh every time.

We will use Verse to control the Scene Graph. The Scene Graph is like a family tree for your island objects. We will pick a random room from that tree and spawn it.

What You'll Learn

  • What the Scene Graph is.
  • How to use Variables to store choices.
  • How to Enable or Disable parts of your island.
  • How to make a room appear at random.

How It Works

Think of your island like a set of LEGO blocks. Each block is an Entity. An Entity is just a thing in the world, like a wall, a door, or a monster.

When you put blocks together, they form a structure. This structure is the Scene Graph. It's a list of all your blocks and how they connect.

We want to pick one block from a group. We use a Variable to remember our choice. A Variable is like a box. You can put something in it, take it out, and put something else in later.

Here is the plan:

  1. We have three different room designs.
  2. We create a box (Variable) to hold the number 1, 2, or 3.
  3. We use a Random Number Generator device. It picks a number for us.
  4. We look at the number. If it is 1, we show Room A. If it is 2, we show Room B.
  5. We hide the rooms we did not pick.

This happens when the game starts. The player joins. The computer picks a room. The room appears. The player walks in. It feels like magic!

Let's Build It

We will write a script that runs when the island starts. It will pick a room and show it.

First, we need to prepare your island in the editor.

  1. Build three different rooms. Call them Room_A, Room_B, and Room_C.
  2. Make sure each room is a separate Entity (a group of props).
  3. In the Verse script, we will use Enable() to show a room and Disable() to hide it.

Here is the code. Copy this into a new Verse file.

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }

# This is our script. It runs when the game starts.
MyRandomDungeon := class(creative_device):

    # These are the rooms. They are creative_prop devices.
    # You must link these in the editor properties.
    @editable
    RoomA : creative_prop = creative_prop{}

    @editable
    RoomB : creative_prop = creative_prop{}

    @editable
    RoomC : creative_prop = creative_prop{}

    # This is the main event. It runs once when the game starts.
    OnBegin<override>()<suspends> : void =
        # 1. Pick a random number between 1 and 3.
        # GetRandomInt returns a value in the range [Low, High] inclusive.
        Choice : int = GetRandomInt(1, 3)

        # 2. Hide all rooms first.
        # We start with a blank slate.
        RoomA.Hide()
        RoomB.Hide()
        RoomC.Hide()

        # 3. Show the room that was picked.
        # We use an 'if' statement. It asks a question.
        if (Choice = 1):
            RoomA.Show()
        else if (Choice = 2):
            RoomB.Show()
        else:
            # If it's not 1 or 2, it must be 3.
            RoomC.Show()```

### Walkthrough

1.  **`using`**: This tells Verse we want to use tools from Fortnite and the Scene Graph.
2.  **`class`**: This is our script template. Think of it as a recipe card.
3.  **`@editable`**: This means you can change these values in the editor. You don't change the code; you change the settings.
4.  **`OnBegin`**: This is the start button. It runs when players join.
5.  **`GetRandomInt(1, 3)`**: This asks for a whole number in the range 1 to 3. It could be 1, 2, or 3.
6.  **`Disable(false)`**: This makes the room invisible and unplayable. It is like turning off a light. The `false` argument means the change happens instantly, without waiting.
7.  **`Enable(false)`**: This turns the room back on. The player can walk in.

## Try It Yourself

You made the rooms appear! Now make it more fun.

**Challenge:** Add a monster to each room. When the room appears, the monster should also appear.

**Hint:**
1.  Create three monster entities: `Monster_A`, `Monster_B`, and `Monster_C`.
2.  Add them to your script as `@editable` variables.
3.  Inside the `if` blocks, call `.Enable(false)` on the matching monster.

For example:
```verse
if (Choice = 1):
    RoomA.Enable(false)
    Monster_A.Enable(false) # Show the monster too!

Recap

  • The Scene Graph is the family tree of your island objects.
  • Variables are boxes that store information, like a random number.
  • You can Enable or Disable entities to show or hide them.
  • Random numbers make your game different every time you play.

References

  • https://dev.epicgames.com/community/snippets/GwWz/fortnite-random-room-spawning-using-scene-graph
  • https://dev.epicgames.com/documentation/en-us/fortnite/hud-message-device-design-example-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite-creative/hud-message-device-design-example-in-fortnite-creative
  • https://dev.epicgames.com/documentation/en-us/fortnite/capture-the-flag-4-set-up-spawn-rooms-in-unreal-editor-for-fortnite
  • https://dev.epicgames.com/documentation/en-us/uefn/capture-the-flag-4-spawn-rooms-in-unreal-editor-for-fortnite

Verse source files

Turn this into a guided course

Add fortnite-random-room-spawning-using-scene-graph 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