So I’m not fully sure what’s the best way to take a Path and see how it would be affected by penalty, per agent. I’ll have to defer that one to @aron_granberg (so I can also find out what’s the best way here)
However in the intermediary I can give you a few useful resources:
First, CanTraverse will check to simply see if you can go from point A to point B. As for, per agent, I’m not 100% sure. This does check if the tags allow it to be walkable, however I’m not sure about the interaction between it and penalties.
Second, you may also get some mileage from ITraversalProvider. There are examples of how this can be used in the Agent-Specific Pathfinding documentation. I have a strong feeling this may be more in line of what you’re looking for?
Thank you very much for your reply! I truly appreciate the support.
To clarify my use case: In my game, I have NPCs that repeatedly walk between two points (A and B). To optimize performance, I cache the path once and reuse it for subsequent trips.
However, since this is a city builder game, the graph can change dynamically. For instance:
If a building is placed, the graph is updated with unwalkable nodes.
Some areas might also be marked with a specific tag that makes them non-traversable for certain agents, depending on their Seeker settings.
Because of this, I need to ensure that the cached path is still valid before reusing it. The key is that this validation should be based on the Seeker’s specific settings (e.g., whether it can traverse certain tags). I don’t want penalties to be considered here since they don’t affect walkability in this context.
Ideally, it would be great if there was a Seeker.IsPathValid(Path path) function that takes a Path object and validates it. However, since this function doesn’t exist, I’m wondering:
What is the next best solution to achieve this?
Is it more efficient to validate a path for reuse, or is it generally faster to simply recalculate the path from scratch?
Looking forward to your thoughts! Thank you for all your hard work on this amazing pathfinding system.
bool IsValid(Path path) {
for (int i = 0; i < path.path.Count; i++) {
if (path.path[i].Destroyed) return false;
if (!path.CanTraverse(path.path[i])) return false;
}
return true;
}
Recalculating a path from scratch is typically not that expensive, though. So unless pathfinding actually shows up in your profiler, I wouldn’t worry too much about optimizing it.
Also. Keep in mind that even if a path stays valid, it may not be the shortest path anymore.
Thanks again for the reply.
Does the Path object contains information about which graph it was calculated on or does the path.CanTraverse just take the first graph it find.