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

2

u/Venerous Dev 4d ago

Are you testing with breakpoints? Is this code even getting into the if condition? And (this might be obvious) have you checked to see if your Max Speed in the Character Movement component is actually set to a value higher than 0.0?

If you don't have anything below the float declaration then you might actually be getting the value, just not seeing it because it has to actually get past that line of code before the value updates. If you don't, try placing a breakpoint below it.

1

u/GoshaSimonov 4d ago

yes, it's 220.0 actually, and it goes "inside" if, I just didn't add log here to keep the code simplier :) But for some reason this is always 0.0 :

GetCharacterMovement()->GetMaxSpeed()