Stop Treating Every Player Like a Chair: Mastering `IsOfClass` in Verse
Tutorial beginner compiles

Stop Treating Every Player Like a Chair: Mastering `IsOfClass` in Verse

Updated beginner Code verified

Stop Treating Every Player Like a Chair: Mastering IsOfClass in Verse

So, you’ve built a trap. It’s beautiful. It’s deadly. It’s also completely broken because it triggers when a friendly NPC walks by, or worse, when a stray dog hops on the pressure plate. You’re trying to make a "Player Only" zone, but Verse is treating every entity in your island like it’s got the same ID tag.

This is where IsOfClass comes in. Think of it as the ultimate bouncer at the club door. It doesn’t care if you’re wearing a gold skin or a banana suit; it only checks if you’re actually a Player (or whatever specific class you’re looking for) and not just some random prop that happened to wander into the line of fire.

In this tutorial, we’re going to build a "VIP Lounge" system. Only players can enter. If a chair, a tree, or a random enemy bot tries to step on the rug, nothing happens. If a human player steps on it, the lights turn green and they get a free healing potion. We’ll learn how to distinguish between a player and everything else in the scene graph.

What You'll Learn

  • The Scene Graph Hierarchy: Understanding that everything in UEFN is an "Entity," but not every Entity is a "Player."
  • IsOfClass: The programming tool that acts like a bouncer, checking if an object belongs to a specific type (class).
  • Event-Driven Logic: Connecting a Trigger Device to Verse code to react when someone crosses the line.
  • Item Granting: Giving players loot programmatically, but only if they pass the ID check.

How It Works

The Scene Graph: Who’s Who?

In Unreal Engine, everything is an Entity. An Entity is just a container for things. Think of it like a locker.

  • A Player is a locker that contains a Character component, a Health component, and an Inventory component.
  • A Chair is a locker that contains a Static Mesh component and a Physics component.
  • A Trigger is a locker that contains a Volume component and some Verse code.

They are all Lockers (Entities). But you can’t sit in a Chair locker and expect to respawn. You need to know what kind of locker you’re dealing with. That’s what Classes are. A Class is the "blueprint" or the "ID badge" of an Entity.

The Bouncer: IsOfClass

Imagine you’re standing at a door. You have a scanner. You point it at someone.

  • If it’s a Player, the scanner beeps "Access Granted."
  • If it’s a Chair, the scanner says "Error: Not Human."
  • If it’s a Storm, the scanner says "Error: Not Human."

IsOfClass is that scanner. It takes an Entity (the person at the door) and a Class (the ID badge you’re looking for, like FortPlayerCharacter) and returns a simple Boolean (a True/False switch).

  • True: "Yes, this Entity is a Player."
  • False: "No, this Entity is a Chair, a Tree, or a Blobfish."

Why Not Just Use "Player" Directly?

You might think, "Why not just tell the code to only listen to players?" Because Trigger Devices in UEFN fire for any collision. If you put a trigger on the floor, it fires when a player walks on it, but it also fires when a rock rolls over it. IsOfClass lets you filter out the noise.

Let's Build It

We are going to create a VIP Healing Pad.

The Setup:

  1. Place a Trigger Volume device in your island. Make it a nice, large square.
  2. Place an Item Granter device. Set it to grant a Chug Jug (or any healing item).
  3. Link the Trigger to the Item Granter using the standard UI (Trigger Output -> Item Granter Input). Wait, don’t do that yet! If you do that, anyone or anything touching the trigger gets a Chug Jug. We want to prevent that.
  4. Instead, we will use Verse to control the Item Granter.

The Verse Code: Create a new Verse file. We’ll call it VIP_Lounge.v.

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

# This is our VIP Lounge Script.
# It listens to the Trigger and only gives loot to Players.
VIP_Lounge := class(creative_device):
    # We need a reference to the Trigger Volume we placed in the editor.
    # Think of this as the "Door Sensor."
    @editable
    Trigger : trigger_device = trigger_device{}

    # We need a reference to the Item Granter.
    # Think of this as the "Loot Dispenser."
    @editable
    Dispenser : item_granter_device = item_granter_device{}

    # This function runs when the game starts.
    # It sets up the connections.
    OnBegin<override>()<suspends>:void=
        # We want to listen for when the Trigger is "Activated" (someone enters).
        # Trigger.TriggeredEvent is an Event. It's like a bell that rings.
        # We attach our function to that bell.
        Trigger.TriggeredEvent.Subscribe(OnTriggerActivated)
        
        # Keep the script alive so it keeps listening.
        loop:
            Sleep(0.0)

    # This function runs every time the Trigger rings.
    # 'Activator' is the thing that stepped on the trigger.
    OnTriggerActivated(Activator : ?agent) : void =
        
        # HERE IS THE MAGIC.
        # We check if the Activator is a Player.
        # If it casts to fort_character successfully, it IS a character.
        if (A := Activator?):
            if (Character := A.GetFortCharacter[]):
                # If it IS a player:
                # 1. Print a message in the debug console (so you know it worked).
                Print("Player entered VIP zone! Healing time.")
                
                # 2. Grant the item.
                # We tell the Dispenser to give an item to the Activator.
                Dispenser.GrantItem(A)
            else:
                # If it is NOT a player (e.g., a chair, a bot, a rock):
                Print("Not a player. Access denied.")
                # Do nothing! No loot for the furniture.```

### Walkthrough of the Code

1.  **`using { ... }`**: These are imports. Think of them as bringing in tools from the toolbox. We need `Devices` to talk to the Trigger and Item Granter, and `Characters` to know what a Player looks like.
2.  **`type VIP_Lounge = struct`**: This defines our script. Its like a custom device you can place in the editor. It has two slots: `Trigger` and `Dispenser`. You will drag and drop your actual devices into these slots in the UEFN editor.
3.  **`OnBegin`**: This runs once when the island starts. We bind the `Trigger.Activated` event to our function. This means "Whenever the trigger is hit, run `OnTriggerActivated`."
4.  **`Activator: Entity`**: When the trigger fires, Verse tells us *what* hit it. It calls that thing the `Activator`. At this point, Verse doesnt know if its a player or a potato.
5.  **`if (Activator.IsOfClass(FortPlayerCharacter))`**: This is the core lesson.
    *   `Activator` is the thing that hit the trigger.
    *   `.IsOfClass(...)` is the check.
    *   `FortPlayerCharacter` is the specific Class ID for human players.
    *   If the check passes, we enter the `if` block. If it fails (its a chair), we skip to the `else` block.
6.  **`Dispenser.GrantItem(...)`**: Only inside the `if` block do we actually give the item. This ensures only players get the loot.

## Try It Yourself

**Challenge:**
Modify the VIP Lounge to be even smarter. Right now, it only checks if the activator is a Player. What happens if a **Team Member** steps on it vs. an **Enemy**?

**Hint:**
You can check for more specific classes. Instead of just `FortPlayerCharacter`, you might look for `FortPlayerCharacter_Athena_C` (Athena players) or check if the activator is on your team.
1.  Find the Class name for an Enemy Character (look in the Verse API documentation for `Enemy` or `Bot`).
2.  Change the `if` statement to check if the activator is an Enemy.
3.  If it *is* an Enemy, instead of giving them a Chug Jug, maybe spawn a **Damage Component** that hurts them! (Youll need to look up `DamageComponent` in the Verse API).

*Dont worry if you cant find the exact enemy class name yetjust try to swap `FortPlayerCharacter` with something else and see what happens when you step on the trigger!*

## Recap

*   **Everything is an Entity**, but they have different **Classes** (IDs).
*   **`IsOfClass`** is your bouncer. It checks if an Entity matches a specific Class (like `FortPlayerCharacter`).
*   Use `IsOfClass` inside your event handlers (like `OnTriggerActivated`) to filter out non-players.
*   This prevents bugs where chairs, bots, or stray items trigger your traps or loot systems.

Now go build something that actually knows the difference between a player and a prop!

## References

- https://github.com/vz-creates/uefn
- https://dev.epicgames.com/documentation/en-us/uefn/verse-api/fortnitedotcom/devices/chair_device/isoccupied
- https://dev.epicgames.com/documentation/en-us/fortnite/scene-events-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/party-game-4-reusable-game-manager-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/fortnite/verse-api/versedotorg/scenegraph/camera_lens

Verse source files

Turn this into a guided course

Add isofclass 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