Add a connection ignoring max distance

I am using a custom point graph. How can I programmatically add a connection from one node to another, ignoring the max distance variable? I have tried adding new connections but it just routes through nodes already there. I want one node to connect to another node directly, even if it is further than the max distance variable.

The reason I can’t just have it connect through current nodes and update the penalties is that I’m looking to have gates. If you enter a gate at node A going to node C, it goes A->B->C. The gate is not enterable from B. I would like pathfinding to prefer the gated connections while still somehow understanding that you can’t enter a gate lane somewhere in the middle.

Hi

programmatically
var node1 = AstarPath.active.GetNearest (positionofNode1).node; var node2 = AstarPath.active.GetNearest (positionofNode2).node; node1.AddConnection (node2, costGoesHere); node2.AddConnection (node1, costGoesHere);

The cost for normal connections is Int3.Precision (set to 1000) multiplied by the world distance.

After modifying the graph you should call
AstarPath.active.FloodFill()
To make sure some pathfinding information is updated.

If you want to do it in a slightly safer way (makes sure there are no race conditions with pathfinding or other graph updates happening at the same time) you can do this.

AstarPath.RegisterSafeUpdate (delegate () { // Do stuff here });

This will make sure all pathfinding threads have been stopped and that no other graph updates are being performed before the callback is called.

Non programmatically
Take a look at the point graph example scene to see an example of how to do it without any code.

Perfect I’ll give it a try, thank you.

Ok, I was hoping that the flood fill was what I was missing but it still isn’t working. Here is a picture showing what is wrong:

The white lines show where there should be special gate lanes. Along the top there are paths but these are the normal node to neighbor node connections, there is no gate lane direct connection. The middle white line again shows where there should be a gate lane but here it is very obvious there is no connection.

This is what I tried tonight. Any ideas why this doesn’t work? It seems to me like it should.

The following code is from my CustomPointGraph.cs after the normal connections based off of distance have been added:

`List forcedConnections;
List newConnections = new List(3);
List forcedConnectionCosts = new List(3);

        foreach(CustomPointNode currentNode in nodes)
        {
            forcedConnections = currentNode.GetAllForcedConnections();

            if (forcedConnections == null)
                return;

            forcedConnectionCosts.Clear();
            newConnections.Clear();

            // Add the forced connections
            if(forcedConnections.Count > 0)
            {

                foreach(CustomPointNode nodeToConnect in forcedConnections)
                {
                    newConnections.Add(nodeToConnect);
                    /** \\todo Is this equal to .costMagnitude */
                    forcedConnectionCosts.Add((uint)Mathf.RoundToInt(0.000001f * Int3.FloatPrecision));
                }
            }

            currentNode.connections = newConnections.ToArray();
            currentNode.connectionCosts = forcedConnectionCosts.ToArray();
        }`

Hm…
That definitely looks like it should work.
Do you think it would be possible for you to create a small example scene (or just your whole project if it is hard to separate) which shows the problem that I could take a look at?

Also, make sure the graph is not scanned after you have modified those connections.

Unfortunately I am at a work site until Thursday and I have incredibly slow internet with many restrictions. I will look into it a bit more tonight and post more information if possible.

I actually managed to force connections tonight but it seems messed up at the moment. I believe that I simply made a mistake somewhere in my caching lists. I will try to fix it up tomorrow, so hopefully I have my system working soon.