Point Graph & NodeLink - Ignore Distance in Costs

I have a point graph that uses “Enemy Waypoint” Gameobjects that are linked together with NodeLink components. These components have a set Cost Factor (usually 1, but some are dynamic and can be higher, like barricaded doorways with varying health).

I’d like for the enemy AI to only consider the costs of the nodelinks to evaluate the best way to the target, but it seems to only consider distance, even through Heuristic is set to None.

These are sample outputs I get when the enemy debugs the different node costs in its path:
Connection from WP to WP: Raw Cost = 8.602, Node Penalty = 0, Distance = 0.008602326
Connection from WP to WP: Raw Cost = 0.156, Node Penalty = 0, Distance = 0.00015625
Connection from WP to WP: Raw Cost = 0.25, Node Penalty = 0, Distance = 0.00025
All of these connections have single NodeLinks with a cost factor of 1 though. No penalties are set either.

Is there a way I can completely ignore the distance of these nodes to each other and purely go off the nodelink costs? Thanks for any help :slight_smile:

Hi

There’s no way to completely ignore the distances between nodes. But you can make the costs of the node links very high, so that they dominate the cost of the path. That will give you essentially what you want.

Note, however, that this will require the pathfinding algorithm to search more nodes than it would otherwise, so it will be slower. This is essential to get the optimal path according to your definition.

Hello Aron! thanks for the reply. Do I understand correctly that simply applying a larger costFactor to all nodeLinks wouldn’t solve my problem, because it multiplies the distance * costFactor? So the resulting path costs would be the same, no matter if I have a costFactor of 1 or 10.000. However if I set dynamic costFactors for each nodeLink, based on the distance between the origin and endpoint, I could make each nodeLink cost roughly the same.

Example:
Path 1 from Point A to point B: path of five nodelinks, each 1 unit apart. Costfactor 1 → Total cost 5.
Path 2 from Point A to point B: path of 3 nodelinks, 2 of them 1 unit apart, one 8 units apart. Costfactor 1 → total cost 10.

These large distances (like the 8 unit one) are teleporters in my game. They look like doors to the player, but move the player long distances along the y axis, as it is a sidescroller. I’ve attached a screenshot below for clarity. If I wanted to make path 2 the first choice (since theleporting actually has 0 distance), I’d have to make the nodeLink of the teleporter a much smaller costFactor, correct?

Yes, you are correct.

I thought you just wanted to ignore all non-off-mesh-link costs.

Great, thank you for the prompt help! I think I’m on the right way now to get this to work :slight_smile:

One more related question. When I update the costFactor of the NodeLink during runtime, is there any way to have the agent work with the updated costs without triggering a full Scan? I’m using the free version.

Hi

Disabling and re-enabling the link should do it, I think.

I somehow couldn’t get this to work using costFactor (even when toggling the link). However, finding the closest node and setting the penalty very high worked for my use case. Just leaving this here in case anyone else has a similar issue.