For anyone looking for the solution here’s mine. Don’t forget to add the EhnancedInput module to your build.cs file. For me, I was missing the EnhancedInputSubsystem which I added to the BeginPlay() function.
They key difference between using a pawn/character and the player controller is…
In the character you are using PlayerInputComponent and in the player controller it’s just called InputComponent. Everything else is basically the same. For me, I prefer to have the actions on the character but I pass the input values in from the player controller. This way I can swap out the possessed pawn and everything will still work using one standardized input setup.
I’ll add more to this as I go.
#include "TGCNP_PlayerController.h"
#include "EnhancedInput/Public/EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
ATGCNP_PlayerController::ATGCNP_PlayerController()
{
}
void ATGCNP_PlayerController::BeginPlay()
{
while (Player == nullptr)
Player = Cast<ATGCNP_Seldin>(GetPawn());
Possess(Player);
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
Subsystem->AddMappingContext(InputMappingContext, 0);
}
void ATGCNP_PlayerController::EnhancedMove(const FInputActionValue& value)
{
if (Player != nullptr)
Player->Move(value);
}
void ATGCNP_PlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
// standard inputs
InputComponent->BindAction("InputUp", IE_Pressed, this, &ATGCNP_PlayerController::InputUp_Pressed);
InputComponent->BindAction("InputDown", IE_Pressed, this, &ATGCNP_PlayerController::InputDown_Pressed);
InputComponent->BindAction("InputRight", IE_Pressed, this, &ATGCNP_PlayerController::InputRight_Pressed);
InputComponent->BindAction("InputLeft", IE_Pressed, this, &ATGCNP_PlayerController::InputLeft_Pressed);
InputComponent->BindAction("InputUp", IE_Released, this, &ATGCNP_PlayerController::InputUp_Released);
InputComponent->BindAction("InputDown", IE_Released, this, &ATGCNP_PlayerController::InputDown_Released);
InputComponent->BindAction("InputRight", IE_Released, this, &ATGCNP_PlayerController::InputRight_Released);
InputComponent->BindAction("InputLeft", IE_Released, this, &ATGCNP_PlayerController::InputLeft_Released);
// enhanced inputs
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
{
EnhancedInputComponent->BindAction(IAJump, ETriggerEvent::Triggered, this, &ATGCNP_PlayerController::EnhancedJump);
EnhancedInputComponent->BindAction(IAMove, ETriggerEvent::Triggered, this, &ATGCNP_PlayerController::EnhancedMove);
}
}