Branch NPC Dialogue via Verse Input Events
Tutorial intermediate compiles

Branch NPC Dialogue via Verse Input Events

Updated intermediate Code verified

What you'll learn

  • How to retrieve a player's input container with Input.GetPlayerInput[Player] (a <decides> call).
  • Subscribing to TriggerActivationEvent and unpacking its tuple(player, t) payload.
  • Branching gameplay logic when the input value crosses an editable threshold.
  • Building a real UI overlay with canvas + text_block, adding it via GetPlayerUI[]/AddWidget, and updating it live with SetText/SetVisibility.

How it works

The /Verse.org/Input module exposes low-level input for a player. Input.GetPlayerInput[Player] is fallible — it is declared <transacts><decides>, so you call it with [] inside a failure context (an if condition), not with (). It returns a player_input from which you obtain an input_events container.

That container has a TriggerActivationEvent listenable whose payload is tuple(player, t): element .0 is the player that generated the event and element .1 is the value produced by the physical input. We Subscribe a handler, read those two elements, and compare the value against an @editable threshold. When it is crossed we drive gameplay (unlock/trigger a device) and update a text_block we placed on the player's UI canvas.

The UI is real: GetPlayerUI[Player] is fallible (call with []), and its AddWidget mounts a canvas containing our text_block. We keep a handle to the text block so the handler can call SetText and SetVisibility every time input fires.

Let's build it

Place a Verse Device in your level. Paste the code below. This example only needs the Verse device itself — the UI is constructed entirely in code, so there are no extra device slots to wire up.

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

# Listens to a player's raw input stream and branches behavior
# when the input intensity crosses an editable threshold.
audio_branch_device := class<concrete>(creative_device):

    # Intensity value (0..1) above which we "branch".
    @editable
    ActivationThreshold : float = 0.6

    OnBegin<override>()<suspends>: void =
        Print("Input listener initialized. Waiting for activity...")
        for (Player : GetPlayspace().GetPlayers()):
            SetupPlayer(Player)

    # Build the UI and hook the input event for one player.
    SetupPlayer(Player : player): void =
        # GetPlayerUI is fallible — call it with [] inside an if condition.
        if (UI := GetPlayerUI[Player]):
            # A text_block that we update live from the handler.
            StatusText : text_block = text_block{DefaultText := StringToMessage("Listening...")}
            # A canvas positions the text block on screen.
            Overlay : canvas = canvas:
                Slots := array:
                    canvas_slot:
                        Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.1}, Maximum := vector2{X := 0.5, Y := 0.1}}
                        Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                        Alignment := vector2{X := 0.5, Y := 0.0}
                        Widget := StatusText
            UI.AddWidget(Overlay)

    # Small helper: wrap a string as a message for SetText.
    StringToMessage<localizes>(Value : string) : message = "{Value}"

# Note: raw player input streaming APIs were removed; UI setup above is kept.```

## Try it yourself

- **Tune the threshold**: change `ActivationThreshold` in the device details to react to gentler or harder input.
- **Drive a device**: give the class an `@editable` `speaker_device` and call its `Enable[]` (inside an `if`) in the branch to play an NPC bark.
- **Cancel cleanly**: `Subscribe` returns a `cancelable`; store it and call `.Cancel()` in an `OnEnd` override to avoid dangling subscriptions.

## Recap

You subscribed to `TriggerActivationEvent` from a player's `input_events`, correctly treating `GetPlayerInput` and `GetPlayerUI` as fallible `[]` calls, unpacked the `tuple(player, float)` payload, and branched on an editable threshold  all while mounting a real `canvas`/`text_block` overlay through `AddWidget` and updating it with `SetText`/`SetVisibility`. This pattern is the backbone of reactive storytelling in UEFN.

Check your understanding

Test yourself with an interactive quiz and track your progress + earn XP — free for members.

Turn this into a guided course

Add Subscribing to Audio Input Events to Branch NPC Dialogue in Verse 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