I have created a custom UActorComponent
that I am creating in my character’s constructor.
However, the issue is that I need this component to be created before SetupPlayerInput()
is called because I bind the input events to handlers in this component:
// Bind movement input
PlayerInputComponent->BindAxis(InputBindings::Movement::GMoveForwardBack, LocomotionComponent, &UPlayerLocomotionComponent::MoveForwardAndBack);
PlayerInputComponent->BindAxis(InputBindings::Movement::GMoveRightLeft, LocomotionComponent, &UPlayerLocomotionComponent::MoveRightAndLeft);
// Bind "look" controls
PlayerInputComponent->BindAxis(InputBindings::Movement::GLookRightLeft, LocomotionComponent, &UPlayerLocomotionComponent::TurnAtRate);
PlayerInputComponent->BindAxis(InputBindings::Movement::GLookUpDown, LocomotionComponent, &UPlayerLocomotionComponent::LookUpAtRate);
This does not work as the function is called before my constructor is called.
The LocomotionComponent
is created in the constructor as follows:
LocomotionComponent = CreateDefaultSubobject<UPlayerLocomotionComponent>(TEXT("LocomotionComponent"));
AddOwnedComponent(LocomotionComponent);