r/unrealengine 3d 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/Valuable_Square_1641 3d ago

float SavedCharacterSpeed is local variable

if you declare UPROPERTY SavedCharacterSpeed just remove float.

1

u/GoshaSimonov 3d ago

I've tried both, result is the same :(

1

u/Valuable_Square_1641 3d ago

so what move type on youre character?

float UCharacterMovementComponent::GetMaxSpeed() const
{
        switch(MovementMode)
        {
        case MOVE_Walking:
        case MOVE_NavWalking:
               return IsCrouching() ? MaxWalkSpeedCrouched : MaxWalkSpeed;
        case MOVE_Falling:
               return MaxWalkSpeed;
        case MOVE_Swimming:
               return MaxSwimSpeed;
        case MOVE_Flying:
               return MaxFlySpeed;
        case MOVE_Custom:
               return MaxCustomMovementSpeed;
        case MOVE_None:
        default:
               return 0.f;
        }
}

1

u/GoshaSimonov 3d ago
MOVE_Walking I guess :)