The Magic Door: Building a Secret Room with Verse
Tutorial beginner compiles

The Magic Door: Building a Secret Room with Verse

Updated beginner Code verified

The Magic Door: Building a Secret Room with Verse

Do you want to build a secret room in Fortnite? What if that room only opens when three friends join you? That is super cool! We will use Verse to make this happen. You will learn how to count players. You will also learn how to open doors based on that count. Let's build a secret clubhouse together!

What You'll Learn

  • What a Player Counter is.
  • How to use Verse to check player numbers.
  • How to open a door when enough players arrive.
  • How to keep your island safe and fun.

How It Works

Imagine you are building a treehouse. You want it to be a secret club. You do not want just anyone to walk in. You want only your best friends. How do you count them?

In Fortnite Creative, we have a special tool called a Player Counter. Think of it like a digital counter on a game show. It keeps track of how many players are in a specific zone.

Here is the plan:

  1. We create a zone. This is an invisible box in the game world.
  2. We place a Player Counter device. It watches that zone.
  3. We write some Verse code. The code asks the counter, "How many friends are here?"
  4. If the answer is three or more, the code sends a signal.
  5. The signal unlocks a door!

This is like a bouncer at a club. The bouncer checks your ID. If you are old enough, he lets you in. Our code is the bouncer. The Player Counter is the ID scanner.

diagram

Count the players in the zone, then branch: open the door only when enough have arrived.

Let's Build It

We will build a simple island. It has a locked door. The door opens when three players stand on a specific spot.

Step 1: Set Up Your Island

First, open UEFN. Create a new island.

  1. Place a Prop Mover. This will be our door.
  2. Place a Trigger Volume where you want the door to open. Make it big enough for three players.
  3. Place a Player Counter device. Connect it to the Trigger Volume.
  4. Place an End Game device or a Prop Mover to act as the door mechanism.

Step 2: The Verse Code

Here is the code. It is short and sweet. Copy this into a Verse file in your project.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is our main script. It runs the show.
# creative_device is the real base class for Verse devices in UEFN.
secret_room_manager := class(creative_device):

    # We need a reference to the door.
    # In Verse, we call things "variables".
    # A variable is like a box that holds a value.
    # Wire this PropMoverDevice in the UEFN Details panel.
    @editable
    Door : prop_mover_device = prop_mover_device{}

    # We need a reference to the Player Counter device.
    # Wire this PlayerCounterDevice in the UEFN Details panel.
    @editable
    Counter : player_counter_device = player_counter_device{}

    # We need a reference to the Trigger device that watches the zone.
    # Wire this TriggerDevice in the UEFN Details panel.
    @editable
    ZoneTrigger : trigger_device = trigger_device{}

    # OnBegin runs when the game starts.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger so we know when a player enters the zone.
        # TriggeredEvent fires each time an agent steps into the trigger volume.
        ZoneTrigger.TriggeredEvent.Subscribe(OnZoneTriggered)

    # This function fires when a player enters the zone.
    # An event is like a trigger. It happens at a specific moment.
    # agent? is the player who walked in — it may be false if no agent caused it.
    OnZoneTriggered(Agent : ?agent) : void =
        # Ask the counter how many players are in the zone.
        # This is like asking a question.
        # # note: player_counter_device exposes GetCount():int as a readable method.
        Count := Counter.GetCount()

        # Check if the count is 3 or more.
        # This is a "condition". It is like a fork in the road.
        if (Count >= 3):
            # If true, open the door!
            # We send a signal to the door.
            Door.End()
            Print("Door is open! Welcome to the club!")
        else:
            # If false, keep the door closed.
            Print("Need more friends! Keep counting...")```

### Walkthrough

Let's look at the code line by line.

*   `using { /Fortnite.com/Devices }`: This tells Verse we want to use Fortnite tools. It is like grabbing your toolbox.
*   `secret_room_manager := class(creative_device)`: This creates our script. `creative_device` is the real base class all Verse device scripts use in UEFN.
*   `@editable Door : prop_mover_device`: This creates a variable named `Door`. It holds the door object. The `@editable` tag lets you wire it up in the UEFN Details panel instead of searching the world in code.
*   `@editable Counter : player_counter_device`: Same idea for the Player Counter device.
*   `@editable ZoneTrigger : trigger_device`: Same idea for the Trigger that watches the zone.
*   `OnBegin<override>()`: This runs first. It connects the trigger's event to our function.
*   `ZoneTrigger.TriggeredEvent.Subscribe(OnZoneTriggered)`: This tells the zone trigger to call `OnZoneTriggered` every time a player steps inside.
*   `Counter.GetCurrentCount[]`: This asks the Player Counter for a number.
*   `if (Count >= 3)`: This checks if there are enough players.
*   `Door.MoveToEnd()`: This moves the prop to its end position, which opens the door!

## Try It Yourself

Now it is your turn to customize the club!

**Challenge:** Change the code so the door opens with only **two** players instead of three.

**Hint:** Look at the line that says `if (Count >= 3)`. Change the number `3` to `2`. Save the code and test it. Does it work?

**Bonus Challenge:** What happens if a player leaves? The door might stay open. Can you find a way to close the door if the count drops below three? (Hint: Look for an `OnPlayerExited` event in Verse!)

## Recap

You built a secret room! You used a Player Counter to count players. You wrote Verse code to check that count. You opened a door when the right number of players arrived. You are now a Verse pro! Keep experimenting. Your island can be anything you imagine.

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite/using-player-counter-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-player-counter-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/design-a-prop-hunt-game-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/design-a-prop-hunt-game-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/stat-counter-design-examples-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-player-counter-devices-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.

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