How to read input value from PlayerController's enhanced input within a Pawn

Hello, I have a Pawn class and a PlayerController class. The PlayerController class handles all the keyboard/gamepad input using enhanced input.

A binding within PlayerController is set up as such:

EnhancedInputComponent->BindAction(MoveForwardAction, ETriggerEvent::Triggered, this, &APLRCNTR_Player::moveForward_);

I am trying to read which input is pressed and what the value is from within the Pawn class, but cannot find anything that would do that.

There is a GetInputAxisValue which I am guessing is from the previous input bindings because I don’t have an FName for the input in enhanced input.

No one knows how I can access the input value from enhanced input?

From the Official Documentation:

void AFooBar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
	{
		UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(PlayerInputComponent);
		// You can bind to any of the trigger events here by changing the "ETriggerEvent" enum value
		Input->BindAction(AimingInputAction, ETriggerEvent::Triggered, this, &AFooBar::SomeCallbackFunc);
	}
	 
	void AFooBar::SomeCallbackFunc(const FInputActionInstance& Instance)
	{
		// Get the value of the Input Action for whatever type you want here...
		FVector VectorValue = Instance.GetValue().Get<FVector>();
		FVector2D 2DAxisValue = Instance.GetValue().Get<FVector2D>();
		float FloatValue = Instance.GetValue().Get<float>(); 
		bool BoolValue = Instance.GetValue().Get<bool>();
	 
		// Do your cool stuff here!
	} 

So in your case, the moveForward_ function should be APLRCNTR_Player::moveForward_(const FInputActionInstance& Instance).

1 Like