How to get simulated path length?

Hello,
I cant find how to get the path length from enemy to player. I want to use it to detect how far is something from player using a pathfinding to know how intense sound has to be in the enemy, like footsteps, etc… So the enemy is not moving to player, just want to simulate the path and know its length. Any ideas?

So… using the path length to attenuate sounds is probably a very bad idea. The path is going to route the enemy around obstacles, and could potentially very long and convoluted. You should just use straight line distance - something like Vector3.Distance(enemy.transform.position, player.transform.position) for this. And possibly do a RayCast between the two positions to see if there’s an obstacle between them that might affect the sound volume.

If you have good reason to use the path length instead of straight-line distance, the Path class has a function GetTotalLength().

Hi

You can do this using something like

var path = seeker.StartPath(transform.position, enemy.position, null);
path.BlockUntilCalculated();
var length = path.GetTotalLength();

However I do agree with DonkeyWorks, this might not be the best idea.
It might be better to just use a raycast and see if there is any obstacle in between the player and the sound and in that case reduce the volume a bit.

See also https://arongranberg.com/astar/docs/callingpathfinding.html
See also https://arongranberg.com/astar/docs/path.html#GetTotalLength

A raycast wouldnt solve anything, as you could be in a room with a wall and in the other side of the wall an enemy, sound should not reduced a bit but completely in most cases