Add an interactable object¶
Designer · 30 min · No code
Result: a lever in the level. Walk up to it and the prompt reads A Pull; press A and the lever does its thing, then stops offering itself. A second action, X Inspect, prints a line instead. No C++.
Before you start¶
- Interaction, NPCs and dialogue: how the prompt picks the one thing it offers, and why the button does exactly what the prompt shows.
- People and chests already have their own classes. Use this recipe for anything else: a door, a lever, a sign, a pickup, a switch.
How it works¶
XenoCoreInteractableActor is a parent class built for Blueprint children. It already does the
parts you would otherwise have to write:
| It does | You do |
|---|---|
| Tells the prompt it exists at Begin Play, and stops at End Play | Nothing. Your own Event BeginPlay cannot skip it |
| Offers its Interact Verb on A and its Secondary Interact Verb on X | Type the two words |
| Checks Interact Enabled and Can Interact before offering itself | Switch it off with Set Interact Enabled, or override Can Interact |
| Calls On Interact with the verb that was pressed | Put the behaviour there |
| Calls On Focused / On Unfocused when the prompt starts or stops offering it | Optional: a highlight |
Two actions, not more. Only A (IA_XenoCore_Interact) and X (IA_XenoCore_InteractSecondary)
have inputs. The base has exactly two verb fields, so it cannot offer a button nothing presses.
Steps¶
1. Create the Blueprint¶
- In
Content/MyGame/World, right-click and choose Blueprint Class. Under All Classes, search forXenoCoreInteractableActorand pick it. Name itBP_MyGame_Lever. - Open it. In Components, the root is Scene Root. Add a Static Mesh under it for the lever (and a collider if the player should bump into it).
- Place the root where the player should stand near. Range is measured from the actor's origin to the player character's location (the middle of its capsule), in 3D, so a root buried in the floor or on a high shelf shortens the effective range.
2. Set the verbs and range¶
Click Class Defaults. Under XenoCore › Interaction:
| Setting | Value | What it does |
|---|---|---|
| Interact Verb | Pull |
The word beside A. Default Use |
| Secondary Interact Verb | Inspect |
The word beside X. Leave empty for no second action |
| Interact Range | 200 |
How close the player must be, in cm |
| Interact Enabled | ticked | Whether the prompt offers this actor at all |
All four are per instance too, so one placed lever can say Push and reach further.
An empty Interact Verb draws a bare button
With Interact Verb empty the prompt shows an A chip with no word, which looks like a broken
widget. The actor logs a warning at Begin Play (LogXenoInteractable: "has an empty Interact
Verb").
3. Handle the press¶
- In the Event Graph, right-click and add Event On Interact. It gives you Interactor (the character that pressed) and Verb Index.
- From Verb Index, call Is Secondary Verb and add a Branch.
- False (A, Pull): do the lever's work (play a timeline, open a door you reference, set a variable), then call Set Interact Enabled with Enabled unticked.
- True (X, Inspect): call Print String with
A rusty lever., or start a conversation with the dialogue nodes (see Write an NPC conversation). - Compile and Save.
Branch on Is Secondary Verb, not on the number
Verb Index is 0 for A and 1 for X today. Is Secondary Verb also returns false when
Secondary Interact Verb is empty, so it stays right if you remove the second action later.
Set Interact Enabled makes the prompt re-decide at once rather than on its next 0.2 s check, so the "A Pull" prompt disappears the moment the lever is pulled.
4. Optional: a condition¶
To offer the lever only sometimes (a key in the bag, a quest step), override Can Interact: Functions › Override › Can Interact. Return true to allow.
Keep Can Interact cheap
The prompt asks every interactable in the level five times a second. Read a variable or a tag; do not trace, spawn or search the level from here.
When Can Interact returns false the lever is skipped, not greyed out: a live interactable standing behind it still gets the prompt.
5. Optional: a highlight¶
Add Event On Focused and Event On Unfocused. For example, set Render Custom Depth on the lever mesh to true and false. They fire once per change: when the prompt starts offering this actor, and when it stops (out of range, disabled, or a menu covers the world).
No focus event on destruction
An actor destroyed while it is focused does not receive On Unfocused. Clean up in Event End Play if a highlight lives on something else.
6. Place it¶
Drag BP_MyGame_Lever into your level. You need nothing else: no ability, no input, no widget.
Test it¶
- Place the lever in
Maps/L_XenoCore_Gymand press Play. - Walk up to it. At about 2 m the prompt beside the player shows A Pull and X Inspect.
- Press X (keyboard F): the message prints; the prompt stays.
- Press A (keyboard E): the lever acts, and the prompt disappears straight away.
- Walk away and back: no prompt, because it is disabled.
If it doesn't work¶
No prompt at all
Check, in order: Interact Enabled is ticked on the placed instance; Can Interact returns true; the player is within Interact Range of the actor's origin; a menu, banner or conversation is not covering the world (the prompt hides then).
Another interactable wins
The prompt offers only the nearest available interactable. An NPC or chest closer to the player takes the prompt. Move them apart or shorten the other's range.
The Blueprint child of an NPC or chest shows a third action that does nothing
NPCs have an Extra Interact Verbs list. The interaction subsystem keeps only the first two
verbs (A and X), drops the rest from the prompt, and logs a warning once per actor
(LogXenoInteract: "offers N verbs but only 2 interact inputs exist"). See
World and maps troubleshooting.
Going further¶
- Remember that it was pulled: add a XenoCore Save Participant component and tick SaveGame on the variable that holds the state. See Make a system save.
- Interaction, NPCs and dialogue
- A third button is a programmer job.
For programmers
A third button needs a new input action, a new interact-press ability, and a raise of
UXenoCoreInteractionSubsystem::MaxPressableVerbs (a constexpr 2). The prompt widget can
draw four.