Video summary

How I Built My Interaction System in Godot (Using Composition)

Main summary

Key takeaways

Technology

Technological concepts & approach (Godot RPG interaction system)

  • Built a vertical slice RPG in Godot (week three), focusing on an interaction system that triggers contextual prompts and actions.
  • Uses a composition-based architecture rather than per-object/branching interaction logic.

Interaction design decisions (pros/cons considered)

  1. Character Area2D + maintain a nearby list

    • Add an Area2D collider to the player and keep a candidate list of nearby interactables.
    • Pros: Immediate interaction on button press; easy to show prompts for the current nearest target(s).
    • Cons: Ongoing per-frame overhead to update/maintain lists and remove stale targets.
  2. On button press, query overlap/intersection

    • Avoids maintaining a continuously updated list.
    • Cons: Potential frame spikes at interaction time; more work on button press.
  3. Raycast interaction

    • Detect the nearest object in front of the player.
    • Pros: No candidate list to manage; naturally selects one target.
    • Cons: More limited to what’s directly in front; finicky collisions and may miss intended targets; less friendly to free movement and requires careful setup.
  4. Objects handle their own proximity/prompt

    • Each interactable object detects player distance and displays prompts.
    • Pros: Localized logic.
    • Cons: Can become messy/non-centralized, hard to debug, possible conflicts between objects vying to control interaction; considered an anti-pattern for this scale.

✅ Chosen solution: Player maintains a list of nearby interactable targets and drives prompts and interaction centrally.

Implemented system architecture (composition pattern)

1) Player-side “Interaction Handler”

  • A drop-in node/handler that manages:
    • A player-centered Area2D (circle) to detect nearby bodies.
    • A candidate list of nearby interaction targets.
    • Per-frame workflow:
      1. Clear/validate candidates
      2. Update each candidate’s distance
      3. Sort candidates by distance
      4. Set the current target to the closest candidate
  • Uses Godot signals for proximity:
    • On body entering: register if it’s an interaction target
    • On body exiting: deregister and remove from candidate list
  • On button press:
    • If a target exists and the pressed interaction index is valid, call interact(...) on the target.

2) Interaction Target component (on each object)

  • Each interactable object gets:
    • An Interaction Target node
    • An Interaction Prompt UI subcomponent (or related prompt logic)
  • Prompts are shown/cleared when the target becomes current/nearby:
    • On start being a target: display prompts
    • On stop being a target: clear prompts
  • The target compiles available behaviors and maps them to button actions via an index.

3) Behavior system (extensible via composition)

  • Behaviors are modular nodes attached under the Interaction Target.
  • A behavior:
    • Extends a shared Interaction Behavior “contract” / base class
    • Defines:
      • interaction name (e.g., “Print”, “Talk”, “Open”, etc.)
      • process interaction(...) logic (what happens when selected)
  • Example behavior implemented: Print behavior
    • When triggered, prints to the console.
  • The Interaction Target scans its children on ready:
    • Builds an array of behavior nodes
    • Generates prompt data based on each behavior’s interaction name and which button/index activates it.

Prompt/UI system and event routing

  • Uses an auto-load event singleton (event service) to avoid wiring UI manually per object.
  • Signals in the event service include at least:
    • Show prompt (with prompt/action data)
    • Hide prompt
  • UI layer (“Interaction Prompt”):
    • A panel with a rich text label
    • Uses screen offset and a stored world position
    • Updates the prompt position every frame so it stays beside the moving target object.
  • Prompt content behavior:
    • If there is an action list, it builds text like:
      • [key/button] Action name per available behavior
    • Otherwise it hides/clears the prompt.
  • Safety/edge handling:
    • When pressing a button by index, it verifies the index exists in the action list; otherwise nothing happens.

Key product/tutorial takeaway

The tutorial demonstrates a scalable interaction system in Godot using:

  • A centralized player-driven proximity list
  • Modular Interaction Target + Interaction Behaviors
  • Decoupled UI via an event singleton
  • Prompt positioning that tracks target movement in screen space

Main speakers/sources

  • Speaker: The tutorial author (first-person narration; “I built…”, “let me show you…”, “this week I got…”).
  • Source: Auto-generated YouTube subtitles from the video “How I Built My Interaction System in Godot (Using Composition)”.

Original video