How to upgrade NodeLink2?

Hi Aron,

How to port NodeLink2 from 4.0 to 5.0 ? I was mainly using startNode & endNode

public PointNode startNode { get; private set; }
public PointNode endNode { get; private set; }

But none of them seem to exist now. I am manually adding the component NodeLink2 to manage specific link.
It is possible to inherit this class to add specific data on it ?

Best

Hi

In v5 you can control how the agent traverses the link by setting the nodeLink2.onTraverseOffMeshLink field. Take a look at the bottom of this page for a code example: Off-mesh links - A* Pathfinding Project
From the callback, you will be able to access more details about the link, and supply your own custom logic.

The nodes themselves are mostly an implementation detail, though.

I saw onTraverseOffMeshLink but how to get both PointNodes ? I mean PointNode startNode & PointNode endNode, nodes that are at the both extremities, the entrance & exit of this link ?

Best

Would you mind detailing what you want to use them for? I think in V5 there are other ways to accomplish the same thing.

We are iterating the returned path nodes, and we are manually computing some data along the path and especially when crossing a link. In links, we are also storing like a constant cost depending on our internal types. So, we need to detect this kind of particular passtrough, there is nothing to do with pathfinding, it is parallel computation for us.

Best

what might work is : use both given transforms of the actual NodeLink2 and retrieve the closest Path Nodes. I mean StartTransform and EndTransform. What do you think ?

Best

Hi

It sounds like rather than accessing the nodes of a link, you want to access the link related to a node?
That can be done. All link nodes in V5 are of the LinkNode type. For example you can access:

LinkNode linkNode = node as LinkNode;
linkNode.linkSource.gameObject.GetComponent<Whatever>();

which will try to get a particular component on the GameObject that the NodeLink2 component is attached to.

In fact, I was looking for both nodes of the link, but I think that it should be fine.

I have another issue with NodeLin2. Is it possible to apply a constant cost for any link ? I have subclassed NodeLink2 where I am storing a constant cost. Do I have to use a costFactor equal to the inverse of the distance between link nodes ?
I was able to do it in v4.0 with a simple patch, but as you said, better to avoid this way.

Best

What do you think of the code below ? :

class NodeLink2Ex : NodeLink2
{
public float constantCost = 0.0f; // cost already include Int3.Precision

public override void Apply()
{
   float dist = Int3.Precision * (StartTransform.position - EndTransform.position).magnitude;
   if (dist > 0)
       costFactor = constantCost / dist;
   else
       costFactor = 1;

   base.Apply();

}

Best

I think that should work, yes.

It’s not possible to set a constant cost out of the box right now.