Hi,
using UE5.6, i´m trying to setup the enhanced input system for my player controller. I have added the dependency in my Build.CS
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });
My Player Controller header looks like this
UPROPERTY(EditAnywhere, Category = "EnhancedInput")
UInputMappingContext* InputMappingContext;
UPROPERTY(EditAnywhere, Category = "EnhancedInput", meta = (AllowPrivateAccess = "true"))
UInputAction* YawInputAction;
public:
void virtual BeginPlay() override;
protected:
void virtual SetupInputComponent() override;
with these implementations
void ASpacePlayerController::BeginPlay()
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::Green, TEXT("EnhancedInputMapped"));
Subsystem->AddMappingContext(InputMappingContext, 0);
}
}
void ASpacePlayerController::SetupInputComponent()
{
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
{
GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::Yellow, TEXT("EnhancedInputBind"));
EnhancedInputComponent->BindAction(YawInputAction, ETriggerEvent::Started, this, &ASpacePlayerController::OnYawInput);
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::Yellow, TEXT("Cast Failed"));
}
}
I can properly set the MappingContext in BeginPlay() (so the Enhanced Input Subsystem is valid), however, in SetupInputComponent(), the PlayerController::InputComponent is not an UEnhancedInputComponent (the respective Cast fails).
I´m wondering if this is the correct way to set things up and why my InputComponent does not seem to be an UEnhancedInputComponent.
Any suggestions?