๐Ÿค Interaction Foundation

Short Description

The Interaction Foundation provides a standardized interface and set of tools for implementing actor interaction and focus logic.

Long Description

The Interaction Foundation simplifies how actors interact with each other in a world. By implementing the IGorgeousInteractionFoundation_I interface, an actor can define its own interaction rules, focus data (like tooltips or highlights), and execution logic. The system includes helper functions for performing common interaction traces (Sphere Trace) and handles the validation of interaction eligibility based on gameplay tags and context.

๐Ÿš€ Features

  • Interface-Driven: Any actor can become interactable by implementing a single interface.
  • Contextual Interaction: Actors can decide if an interaction is possible based on who is interacting with them.
  • Rich Focus Data: Provide custom data structures (via FInstancedStruct) when an actor is focused.
  • Trace Helpers: Standardized Blueprint nodes for sphere-trace based interaction and focus.
  • Tag-Based Logic: Use FGameplayTag to categorize different types of interaction (e.g., Interaction.Type.Pickup, Interaction.Type.Talk).

๐Ÿ“š Usage Examples

FGameplayTagContainer Tags;
if (UGorgeousInteractionFoundationBlueprintFunctionLibrary::TryRequestInteractionTags(TargetActor, Tags))
{
    // Handle tags
}

Use Try Sphere Trace Focus on every tick (or timer) to detect interactable objects in front of the player. If it returns true, update your UI with the provided OutFocusData.

TryRequestInteractionTags

Queries the target actor for its supported interaction tags.

Parameter Name Type Description
TargetActor AActor* The actor to query.
Parameter Name Type Description
OutInteractionTags FGameplayTagContainer The container that will be filled with the actor's tags.

TryCanInteract

Checks if interaction is currently allowed between the target and the interactor.

Parameter Name Type Description
TargetActor AActor* The interactable target.
InteractingActor AActor* The actor attempting to interact.

TryFocus

Requests focus-specific data from the target actor. Used for tooltips, UI prompts, or visual highlights.

Parameter Name Type Description
TargetActor AActor* The focused target.
InteractingActor AActor* The focusing actor.
Parameter Name Type Description
OutFocusData FInstancedStruct The data payload provided by the target.

TryInteract

Executes the interaction logic on the target actor.

Parameter Name Type Description
TargetActor AActor* The target to interact with.
InteractingActor AActor* The actor performing the interaction.
HitResult FHitResult Spatial context for the interaction.

TrySphereTraceFocus

Performs a sphere trace and automatically queries the hit actor for focus data if it implements the interaction interface.

Parameter Name Type Description
TraceParameters FGorgeousInteractionSphereTraceParameters Configuration for the trace (radius, length, channel).
InteractionTag FGameplayTag The type of interaction being focused on.

๐Ÿ—๏ธ Interaction Flow

sequenceDiagram
    participant P as Player
    participant Lib as Interaction Lib
    participant T as Target Actor
    
    P->>Lib: TrySphereTraceFocus()
    Lib->>T: Interface: GetFocusData()
    T-->>Lib: Focus Data (Payload)
    Lib-->>P: Success + Payload
    Note over P: Show UI Prompt
    P->>Lib: TryInteract()
    Lib->>T: Interface: ExecuteInteraction()

Best Practices

  • Interface Implementation: Always ensure your interactable actors implement IGorgeousInteractionFoundation_I via the Class Settings in Blueprint.
  • Trace Distance: Keep sphere trace distances reasonable (e.g., 2-3 meters) to prevent players from interacting with objects through walls or from too far away.
  • Focus Payloads: Use a dedicated data structure for your focus data to keep your UI prompts consistent across different types of interactables.

Troubleshooting

  • Interaction Not Triggering: Ensure the target actor implements the interaction interface and that the collision channel used in the trace matches the target's collision profile.
  • Null Focus Data: If TryFocus returns true but the FInstancedStruct is empty, check the implementation in the target actor to ensure the payload is being correctly assigned.