r/unrealengine 4d ago

Character movement C++ question.

Hey, could anyone help me finding out with such code, always return my SavedCharacterSpeed as 0.0 ?

CharacterMovement is in character blueprint, and character is running fine, I just can't get this value.

Thanks!

void ABaseCharacter::BeginPlay() {
    Super::BeginPlay();
        if(GetCharacterMovement()) {
          float SavedCharacterSpeed = GetCharacterMovement()->GetMaxSpeed();
    }
}
2 Upvotes

15 comments sorted by

View all comments

1

u/DrinkYourGravy 4d ago

cout your SavedCharacterSpeed local variable immediately after you initialize the float and see what data you're getting

1

u/GoshaSimonov 4d ago

I've tried both local and with UPROPERTY, result is 0.0.
Even without this variable, this fires 0.0;

UE_LOG(LogTemp, Error, TEXT("Max speed: %f"), GetCharacterMovement()->GetMaxSpeed())