How do I calculate the total distance traveled walking around environments?

I need to calculate the total distance my pawn moves around an environment, not just from point A to point B. I want to constantly subtract a variable as my pawn moves a certain distance going forward / backwards / left / right. Is there a way to keep updating location and track this?

Any help/direction is appreciated, Thanks!

I would put it where you’re setting/updating the position of the player’s pawn.

At some point in some blueprint you’re calling something like “Add To World Location” or similar.
When doing that, calculate the length of the vector you’re adding to the current position and decrement your global distance counter by that length.

The formula for the length would be sqrt( x^2 + y^2 ) when only using X and Y movement for calculating the traveled distance, it gets a bit more complex when actually taking X, Y and Z movement differences into account.

i get the way you are trying to calculate the distance but sqrt(x^2+y^2) will give the displacement vector from the origin but i want the actual distance travlled as i have made a endless runner game wich can turn 90 degrees so this method wont work in that if you know anyother way pls tell me

Get the velocity at every frame and then calculate the distance traveled with velocity/speed * time. Velocity/Speed should be easily accessible in the player’s movement component.

edit: I meant velocity and/or speed * time, not velocity divided by speed times time.

edit 2: APawn::GetVelocity().Size() * DeltaSeconds is what you want in your Tick function.