The Ghost in the Machine: Understanding "Source" in Verse
Tutorial beginner compiles

The Ghost in the Machine: Understanding "Source" in Verse

Updated beginner Code verified

The Ghost in the Machine: Understanding "Source" in Verse

You know that feeling when you're building a trap in Fortnite, and suddenly a Tilted Towers player slides out of nowhere, eliminates you, and you're left staring at your own grave? That's not just bad luck. That's data moving from one place to another.

In Verse, everything is connected. When a bullet hits a wall, when a player picks up a shield potion, or when a trap triggers, information has to travel. It has to come from somewhere and go to somewhere else. In programming terms, we call the origin point the Source.

Think of the Source like the Battle Bus. It's the starting point. The bus launches, players jump out, and they land on the island. The bus didn't change, but the players (the data) moved from the bus (the source) to the ground (the target). If you want to build complex systems—like a trap that only triggers if the player is behind a wall, or a loot drop that appears above a specific chest—you need to know exactly where that data came from.

In this tutorial, we're going to stop guessing where data comes from. We're going to learn how to identify the Source of an event so you can build traps that are actually smart, not just loud.

What You'll Learn

  • What a Source is in the context of Verse and game logic.
  • How to distinguish between the thing that caused an event and the thing that received it.
  • How to use Sweep and Overlap events to grab the Source's position and identity.
  • How to build a "Revenge Trap" that knows exactly who killed it and where it died.

How It Works

The "Who Did It?" Problem

Imagine you place a pressure plate. You step on it, and a ceiling fan spins. Simple, right?

Now, imagine you want to make a trap that says, "Hey, Player X stepped on me!" To do that, the trap needs to know who stepped on it. It can't just spin the fan; it needs to read the identity of the person who triggered it.

In Verse, when an event happens (like a collision), the engine gives you a package of information. This package contains two main characters:

  1. The Source: The thing that initiated the action. (e.g., The player's character mesh, a bullet, a falling rock).
  2. The Target: The thing that got hit. (e.g., The pressure plate, the wall, the floor).

If you don't grab the Source, you're flying blind. You might know something hit the plate, but you won't know what hit it. Did a chicken peck it? Did a player step on it? Did a grenade explode nearby? Without capturing the Source, your trap is just a glorified button.

Scene Graph: The Family Tree of Objects

Before we look at code, you need to understand the Scene Graph. This is just a fancy way of saying "the hierarchy of everything in your game."

Imagine a family tree.

  • Your Player is the parent.
  • The Player's Character Mesh (the 3D model you see) is the child.
  • The Player's Hitbox (the invisible box that detects collisions) is a grandchild.

When a bullet hits your player, it doesn't hit the "Player" object directly. It hits the Hitbox (the child). The Source of that collision is the Bullet. The Target is the Hitbox.

In Verse, we often use Components and Volumes. A Component is a piece of an entity (like a mesh or a collision box). A Volume is an invisible 3D shape used for detection. When we talk about the SourceComponent or SourceVolume, we're asking: "Which specific part of the Source object did the collision happen on?"

Sweep vs. Overlap: How Data Travels

There are two main ways Verse detects interactions, and both give you the Source:

  1. Overlap: This is like a ghost walking through a wall. It checks if two objects are currently touching. If a player stands in a zone, it's an overlap. The Source is the player. The Target is the zone.
  2. Sweep: This is like firing a raycast or a bullet. It moves from Point A to Point B and checks what it hits along the way. The Source is the starting point of the ray. The Target is whatever the ray hit first.

Why does this matter? Because Sweep gives you more detail. It tells you the SourceStartGlobalTransform (where the ray started) and the SourceHitDistance (how far it traveled before hitting something). This is crucial for building "line-of-sight" traps or sniping mechanics.

Let's Build It

We're going to build a "Revenge Trap."

Here's the scenario: You place a trap on the floor. If a player steps on it, it doesn't just explode. It plays a sound effect that says (via text chat or a visual cue) "You were eliminated by [Player Name]!" and then it eliminates the player.

To do this, we need to:

  1. Detect when a player overlaps with the trap.
  2. Grab the Source of that overlap (the player).
  3. Eliminate the Source.

The Code

Here is a complete Verse script for a custom trap device. You can paste this into a Verse script in UEFN.

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

# 1. Define our Trap Device
revenge_trap_device := class(creative_device):

    # This is the 'Target' zone. When a player enters, this triggers.
    # Wire this in UEFN to a Trigger device placed in your level.
    @editable
    TriggerDevice : trigger_device = trigger_device{}

    # 2. The Core Logic: Overlap via trigger_device
    # This function runs when an agent activates the TriggerDevice
    OnTriggered(Agent : ?agent) : void =
        # Check if the 'Agent' is a fort_character (i.e. has a game character)
        if (ActualAgent := Agent?, FortCharacter := ActualAgent.GetFortCharacter[]):
            # HERE IS THE KEY PART:
            # 'Agent' IS the Source of the overlap.
            # We don't need to look it up; it's right there!

            # Let's do something with the Source (the player character)
            # Eliminate them via damage — fort_character exposes Damage()
            FortCharacter.Damage(9999.0)

            # Optional: Print to console to prove we know who the Source is
            # In a real game, you'd probably send a message to the player's chat
            Print("Revenge Trap activated! Source was an agent.")

    # 3. Initialization
    OnBegin<override>() <suspends> : void =
        # Connect the trigger's TriggeredEvent to our handler function.
        # This tells Verse: "When TriggerDevice fires, run OnTriggered"
        TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)```

### Walkthrough: What Just Happened?

1.  **`revenge_trap_device := class(creative_device):`**
    We're creating a new device type. Think of this as designing the blueprint for the trap.

2.  **`@editable TriggerDevice : trigger_device`**
    This is our **Target**. A `trigger_device` is a UEFN Trigger device you place in the level and wire to this script. Anything that walks into the trigger zone is a potential **Source** of an event. The `@editable` attribute lets you assign it in the UEFN details panel.

3.  **`OnTriggered(Agent : agent)`**
    This is the function that runs when the **Source** enters the **Target**.
    *   `Agent` is the **Source**. It's the thing that moved into our trap's zone.
    *   `agent` is the base Verse type for any entity that can take actions (players, NPCs).

4.  **`if (FortCharacter := Agent.GetFortCharacter[]):`**
    We're checking: "Does this Source have a Fortnite character body?"
    *   If the Source is something without a character (like a prop), this fails, and nothing happens.
    *   If the Source is a player or NPC, `FortCharacter` becomes that specific character object.

5.  **`FortCharacter.Damage(9999.0)`**
    We use the **Source**'s character (the `fort_character`) to trigger an action. Because we captured the Source, we can manipulate it directly. A very large damage value ensures elimination.

6.  **`Print(...)`**
    This is just for you. It confirms that Verse knows exactly who the Source was.

### Why Not Just Use a Trigger?

You *could* use a simple Trigger device in UEFN. But triggers are dumb. They don't tell you *who* triggered them. They just say "Something happened."

With Verse, by capturing the **Source** in the `OnTriggered` function, you have full control. You can:
*   Get the player's name.
*   Get the player's health.
*   Teleport the player.
*   Give them a weapon.
*   Eliminate them.

The **Source** is the key that unlocks all of these possibilities.

## Try It Yourself

Now that you know the **Source** is the `Agent` in a trigger event, try this:

**Challenge:** Modify the `revenge_trap_device` so that it *heals* the player instead of eliminating them, but only if the player's health is below 50.

**Hint:**
1.  Inside the `if (FortCharacter := Agent.GetFortCharacter[]):` block, check `FortCharacter.GetHealth()`.
2.  If the health is less than 50.0, call `FortCharacter.SetHealth(FortCharacter.GetHealth() + 50.0)`.
3.  If the health is 50 or more, do nothing (or maybe play a "nope" sound).

Don't forget: The **Source** is still `FortCharacter`. You're just changing what you do with it.

## Recap

*   **Source** is the thing that *initiates* an action or collision.
*   In an **Overlap** event, the **Source** is the actor that entered the volume.
*   In a **Sweep** event, the **Source** is the object that started the sweep (like a bullet or ray).
*   Always capture the **Source** early in your logic so you can use its properties (name, health, location) to make smart decisions.
*   Without the **Source**, you're just reacting to noise. With it, you're building intelligent systems.

## References

- https://dev.epicgames.com/documentation/en-us/fortnite/using-livelink-hub-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/using-livelink-hub-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/fortnite/verse-api/versedotorg/scenegraph/sweep_hit
- https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/versedotorg/scenegraph/overlap_hit
- https://dev.epicgames.com/documentation/fortnite/verse-api/versedotorg/scenegraph/overlap_hit

Verse source files

Turn this into a guided course

Add Sources Panel 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