The same action and axis mappings in the game’s input project settings can be used from C++.
AMyPawn::AMyPawn()
{
PrimaryActorTick.bCanEverTick = true;
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("X_Button", IE_Pressed, this, &AMyPawn::XPressed);
PlayerInputComponent->BindAction("L_GripAxis", this, &AMyPawn::LeftGripAxis);
}
void AMyPawn::XPressed()
{
UE_LOG(LogTemp, Log, TEXT("X Pressed"));
}
void AMyPawn::LeftGripAxis(float AxisValue)
{
if(AxisValue != 0.0f)
{
UE_LOG(LogTemp, Log, TEXT("Left Grip Axis Valule: %f"), AxisValue);
}
}
private:
void XPressed();
void LeftGripAxis(float AxisValue);
When using thumbstick axis events, the name of the axis event must end in “_X” or “_Y” corresponding to the key used.
Finally, register the actions in the game with SteamVR by using the Regenerate Action Manifest and Regenerate Controller Bindings buttons in Project Settings > Steam VR Input.