I have a custom movement component that I’m using with a custom character. My custom movement component is like this:
UCLASS()
class UBreakdanceMovementComponent : public UCharacterMovementComponent
{ ...
And my character class has a constructor like this:
ABBoyCharacter::ABBoyCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UBreakdanceMovementComponent>(ACharacter::CharacterMovementComponentName))
{
UBreakdanceMovementComponent* movement = GetCharacterMovement<UBreakdanceMovementComponent>();
movement->CreateCardboard(FVector(5,5,1));
...
This works fine, I can use GetCharacterMovement in the constructor and it’s the right type of class. But I also have an input action bound to a key, and when I call it there it crashes because the cast is saying it’s a normal UCharacterMovementComponent, not my custom class. Ie, in the input function:
void ABBoyCharacter::Spin(const FInputActionValue& Value)
{
UBreakdanceMovementComponent* movement = GetCharacterMovement<UBreakdanceMovementComponent>();
if(movement->HasCardboard())
...
That same typecasted call to GetCharacterMovement fails even though it worked fine in the constructor.
What?? Why?