Download

Modify Nav Movement attributes in C++ (On UCharacterMovementComponent)

It wont let me post an image so here is a direct link:

http://https://i.imgur.com/nKivSKe.png

I’m trying to modify the variables that can be seen in blueprints, on an inherited CharacterMovementComponent on a character class.

The class is based on a c++ class that inherits from UCharacter.

In the class, I am able to modify certain variables of the CharacterMovementComponent.



// CharacterMovementComponent configuration
UCharacterMovementComponent* cmp = GetCharacterMovement();
cmp->bOrientRotationToMovement = true;
cmp->RotationRate.Yaw = TurnRate;
cmp->MaxWalkSpeed = Speed;
cmp->MaxAcceleration = 1000;


However, I also want to modify these values:
Fixed Path braking distance.
Use acceleration for Paths
Use Fixed Braking Distance for Paths

How do I access these? I tried casting the character movement component to an nav movement component, but still cannot access them.

Thanks

You don’t need the cast because the Character Movement Component IS a UNavMovmentComponent.

Those properties however are protected, so you can only modify them from within the character movement component class. This is probably to ensure you don’t modify properties that have no effect if changed at runtime.

Some of them do have accessor functions however, such as SetFixedBrakingDistance() which you can call from anywhere.

Hi, thanks for your reply.

So this means that I pretty much HAVE to modify these in blueprints, and not in code?

J

You can modify them in code, but you can only modify protected variables in a child of that specific class - not anywhere else. Blueprint probably won’t help you there either since I don’t think any of this is exposed, but there are accessors functions you can call in c++ to change values.

They are definitely exposed in the blueprint editor (not sure if its by variable or function) as you can see in the image on my post.

I guess my question should be, what is the class to call from, and what are the functions to call / attributes to modify that directly correlate with that image?

Thanks

J

Hi! I’m looking for the same thing and can’t seem to find it anywhere. Any update on this?

Hi Guys,

Those boolean variables would only be accessible directly by subclassing UCharacterMovementComponent (or your chosen nav movement derivative) and creating setter functions.

However, you can get to the fixed braking distance boolean and float indirectly via UNavMovementComponent::SetFixedBrakingDistance(float DistanceToEndOfPath). I added a blueprint callable function to my character class like so:



UFUNCTION(BlueprintCallable)
    void SetFixedBrakingDistance(float BrakingDistance);




void AAICharacter::SetFixedBrakingDistance(float BrakingDistance)
{
    GetCharacterMovement()->SetFixedBrakingDistance(BrakingDistance);
}


The body of that function sets bUseFixedBrakingDistanceForPaths to true if the value is greater than zero. Inversely, you can call ClearFixedBrakingDistance to set it to false.

Without sub classing the movement component, you can’t get to bUseAccelerationForPaths.