Skip to main content

Quick Start (C++)

This walkthrough assumes you already have custom APlayerController / AGameStateBase / AActor classes.

1) PlayerController: add UEDPlayerInteractionComponent

// MyPlayerController.h
#include "GameFramework/PlayerController.h"
#include "MyPlayerController.generated.h"

class UEDPlayerInteractionComponent;

UCLASS()
class AMyPlayerController : public APlayerController
{
GENERATED_BODY()

public:
AMyPlayerController();

protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<UEDPlayerInteractionComponent> InteractionComponent;
};
// MyPlayerController.cpp
#include "MyPlayerController.h"
#include "Components/EDIPlayerControllerComponent.h"

AMyPlayerController::AMyPlayerController()
{
InteractionComponent = CreateDefaultSubobject<UEDPlayerInteractionComponent>(TEXT("EDPlayerInteraction"));
}

2) GameState: add UEDInteractionGameStateComponent

// MyGameState.h
#include "GameFramework/GameStateBase.h"
#include "MyGameState.generated.h"

class UEDInteractionGameStateComponent;

UCLASS()
class AMyGameState : public AGameStateBase
{
GENERATED_BODY()

public:
AMyGameState();

protected:
UPROPERTY(VisibleAnywhere)
TObjectPtr<UEDInteractionGameStateComponent> InteractionGameStateComponent;
};
// MyGameState.cpp
#include "MyGameState.h"
#include "Components/EDInteractionGameStateComponent.h"

AMyGameState::AMyGameState()
{
InteractionGameStateComponent = CreateDefaultSubobject<UEDInteractionGameStateComponent>(TEXT("EDInteractionGameState"));
}

3) Interactable actor: add UEDInteractableComponent

// MyInteractableActor.h
#include "GameFramework/Actor.h"
#include "MyInteractableActor.generated.h"

class UEDInteractableComponent;

UCLASS()
class AMyInteractableActor : public AActor
{
GENERATED_BODY()

public:
AMyInteractableActor();

protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<UEDInteractableComponent> InteractableComponent;
};
// MyInteractableActor.cpp
#include "MyInteractableActor.h"
#include "Components/EDInteractableComponent.h"

AMyInteractableActor::AMyInteractableActor()
{
InteractableComponent = CreateDefaultSubobject<UEDInteractableComponent>(TEXT("EDInteractable"));
}

4) Input binding

Call UEDPlayerInteractionComponent::Interact(bool bEntering) from your input bindings:

  • Pressed: Interact(true)
  • Released: Interact(false)

EDInteractionSystem is compatible with either legacy input or Enhanced Input.