Hi all,
I’m trying to use the Enhanced Input for the first time and I can’t get it to work.
Procedure I’ve followed:
Created the Enhanced Input action and Input mapping context in editor and assigned the values in both.
In the PlayerController.h I’ve added the below code.
public:
// Your Mapping Context and Actions
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
UInputMappingContext* RaceMappingContext;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
UInputAction* IA_IncreaseSpeed;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
UInputAction* IA_DecreaseSpeed;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
UInputAction* IA_Pause;
in the PlayerController.cpp, in beginplay
void ARaceManagerPlayerController::BeginPlay()
{
Super::BeginPlay();
// Add your mapping context when the game starts
if (UEnhancedInputLocalPlayerSubsystem* Subsystem =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
if (RaceMappingContext)
{
Subsystem->AddMappingContext(RaceMappingContext, 0);
}
}
Then I created the BP from c++ class, in the BP I’ve added the context and actions.
then I’ve added this player controller to the game mode BP.
Now, when the BeginPlay hits, RaceMappingContext is null, so are all the UInputAction s. Is there a step I’m missing here?
Any help is much appreciated.
Thanks in advance!