Interactable Interface {{ currentPage ? currentPage.title : "" }}

Documentation for the ACF Interaction System


Overview

The ACF Interaction System enables robust detection and interaction with in-game objects within Unreal Engine. By utilizing the UACFInteractionComponent, developers can easily allow characters or pawns to detect nearby interactable objects, determine the best candidate for interaction, and perform the corresponding actions. This system supports multiplayer environments with replication and provides extensive customization options.


Core Features

  1. Detection of Interactable Objects:

    • Uses collision to detect interactable actors within a specified radius.

    • Supports dynamic registration and unregistration of interactable objects.

  2. Best Interaction Selection:

    • Dynamically determines the closest interactable object based on conditions.

    • Ensures smooth updates when objects enter or leave the interaction area.

  3. Interaction Execution:

    • Supports both local and server-side interaction handling.

    • Invokes methods defined in the UACFInteractableInterface.

  4. Replication:

    • Ensures interaction states and updates are synchronized in multiplayer environments.

  5. Customizable Detection:

    • Provides control over collision channels and detection areas.


Key Classes and Components

UACFInteractionComponent

The core component that manages interaction detection and execution.

  • Responsibilities:

    • Detects nearby interactable objects using collision.

    • Selects the best interactable object based on proximity and conditions.

    • Handles interactions initiated by the owning pawn or character.

  • Key Properties:

    • InteractableArea: Radius for detecting interactable objects.

    • currentBestInteractableActor: Reference to the closest interactable object.

    • CollisionChannels: List of collision channels used to filter detected objects.

  • Key Methods:

    • EnableDetection(bool bIsEnabled): Enables or disables detection of interactable objects.

    • Interact(const FString& interactionType): Performs an interaction with the current best interactable.

    • SetCurrentBestInteractable(AActor* actor): Updates the currently selected interactable object.

    • RefreshInteractions(): Reassesses interactable objects and determines the best candidate.

    • AddCollisionChannel(TEnumAsByte<ECollisionChannel> inTraceChannel): Adds a collision channel for interaction detection.

    • RemoveCollisionChannel(TEnumAsByte<ECollisionChannel> inTraceChannel): Removes a collision channel.

  • Events:

    • OnInteractionSucceded: Broadcasts when an interaction is successfully performed.

    • OnInteractableRegistered: Broadcasts when a new interactable object is registered.

    • OnInteractableUnregistered: Broadcasts when an interactable object is unregistered.


Customization and Extensibility

  1. Custom Interaction Logic:

    • Implement the UACFInteractableInterface on any actor to define custom interaction behavior.

    • Override methods like OnInteractedByPawn and OnLocalInteractedByPawn for tailored responses.

  2. Detection Radius:

    • Adjust the InteractableArea property to control the interaction detection range.

  3. Collision Channels:

    • Add or remove collision channels to include specific object types in the detection logic.

  4. Events and Broadcasts:

    • Bind to OnInteractionSucceded, OnInteractableRegistered, and OnInteractableUnregistered for custom interaction responses.


Example Usage

Enabling Detection

UACFInteractionComponent* interactionComp = ...; // Retrieve the interaction component
interactionComp->EnableDetection(true); // Enable interaction detection

Adding a Collision Channel

interactionComp->AddCollisionChannel(ECC_GameTraceChannel1); // Add a custom collision channel

Performing an Interaction

interactionComp->Interact("PickupItem"); // Trigger an interaction with the closest interactable object

Implementing an Interactable Object

// MyInteractableActor.h
class AMyInteractableActor : public AActor, public IACFInteractableInterface
{
    GENERATED_BODY()
public:
    virtual bool CanBeInteracted(AActor* Interactor) override;
    virtual void OnInteractedByPawn(AActor* Pawn, const FString& InteractionType) override;
    virtual void OnLocalInteractedByPawn(AActor* Pawn, const FString& InteractionType) override;
};
// MyInteractableActor.cpp
bool AMyInteractableActor::CanBeInteracted(AActor* Interactor)
{
    return true; // Add custom logic to determine if interaction is allowed
}
void AMyInteractableActor::OnInteractedByPawn(AActor* Pawn, const FString& InteractionType)
{
    UE_LOG(LogTemp, Log, TEXT("Interacted by: %s with action: %s"), *Pawn->GetName(), *InteractionType);
}
void AMyInteractableActor::OnLocalInteractedByPawn(AActor* Pawn, const FString& InteractionType)
{
    // Local interaction logic (e.g., client-side effects)
}

Conclusion

The ACF Interaction System provides a powerful and flexible framework for implementing interaction mechanics in Unreal Engine. By leveraging the UACFInteractionComponent and the UACFInteractableInterface, developers can create seamless, responsive, and highly customizable interactions between characters and in-game objects. The system's modularity ensures it can be adapted to a variety of gameplay scenarios while supporting both single-player and multiplayer environments.

{{{ content }}}