How to Ensure component created before SetupPlayerInputComponent?

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);

Ok, I solved this… So I’ll answer my own question if anyone encounters the same problem.

So it turns out that Hot Reload was the culprit and my BP was corrupted…

Solution: I created a new BP child class and it worked… I’ve also learnt to not use Hot Reload…

1 Like