UE4 C++绑定按键输入

Actor内有一个已经预先定义的InputComponent 需要将其进行实例化、绑定即可, 最后要启用输入的接收

//Pawn、Character、Player Controller已经预先实例化了,不需要实例化,Actor才需要实例化
InputComponent = NewObject<UInputComponent>(this);
InputComponent->RegisterComponent();
//绑定
if (InputComponent)
{
    //这里常规绑定即可
    InputComponent->BindAction("ActionName", IE_Pressed, this, &AFlatSword::Fun);
    //启用输入
    EnableInput(GetWorld()->GetFirstPlayerController());
}