Hello, I have assigned the “C” key to crouch and I want to print the text on the screen “Crouch Successful” when the “C” key is pressed. I want to do it in C++.
If you want to make some action when your binding is executed (e.g. when C is pressed and C is bound to “Crouch” in project settings), you can just bind a function to that action.
For example, in your character class, you can setup input component (in other places as well):
void ADungeonGameCharacter::SetupPlayerInputComponent(UInputComponent* const PlayerInputComponent)
{
check(PlayerInputComponent);
// Bind crouch action, so whenever executed it will call CrouchPressed function on this object
PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ADungeonGameCharacter::CrouchPressed);
}
void ADungeonGameCharacter::CrouchPressed()
{
// Print to screen
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Crouch Successfull!"));
}
I would recommend looking at some game templates provided with the engine, e.g. the first person template.
More on input component https://docs.unrealengine.com/4.26/en-US/API/Runtime/Engine/Components/UInputComponent/
Super Thanks )