Support Forum

Point graph not functional after RelocateNodes

Hi,

I have an issue where point graphs that are moved using RelocateNodes are not being included in pathfinding.

For some back story, I am making a game with procedural dungeons where rooms link together. I add a surface in between the doors that the Recast pathfinder will use as a potential area to move between the rooms.

The Recast graphs work, I translate it using the same matrix calculation as the point graphs. The enemies are able to traverse between rooms that are loaded in from a cache and relocated. The problem is, they are fine in the room where the original cache is from, but enemies from another room are not able to pathfind including their node links. The behaviour I see from the second room is that the moment I go to a higher position, they run in circles. In the same area in the original room, they are able to jump. I am loading the same cache (as it is the same room twice for testing purposes) and I start with an empty pathfinder.

When the pathfinder is in play mode, both graphs are loaded from the same cache and relocated for each room:

Limited, click here for image

This is an image of the original room, with a loaded cache and relocated nodes (they aren’t moved from original position, the matrix is essentially blank, but it is loaded in)

image

This is an image of the second room, seemingly identical, and loaded the same way. The matrix would be a 180 degree rotation and a slight offset in position.

image

This is my code to relocate the nodes:

       AstarPath.active.data.DeserializeGraphsAdditive(AStarCache.bytes); 
        
        Matrix4x4 graphMatrix = Matrix4x4.identity;
        graphMatrix *= Matrix4x4.Translate(transform.position);
        graphMatrix *= Matrix4x4.Rotate(transform.rotation);
        graphMatrix *= Matrix4x4.Translate(-transform.position);
        graphMatrix *= Matrix4x4.Translate(transform.position - startingPosition);

        var graphs = AstarPath.active.graphs;

        int pointGraphIndex = graphs.Length - 1;
        int recastGraphIndex = graphs.Length - 2;

        if (graphs[pointGraphIndex] is PointGraph)
        {
            Debug.Log("Moving a point graph!");
            var g = graphs[pointGraphIndex] as PointGraph;
            g.RelocateNodes(graphMatrix);
            g.Scan();
        }

        if (graphs[recastGraphIndex] is RecastGraph)
        {
            Debug.Log("Moving a recast graph!");
            var g = graphs[recastGraphIndex] as RecastGraph;
            g.RelocateNodes(graphMatrix);
        }

Here is a video of the behaviour.

Hi

Hmm, you may need to move the actual node link objects too. Right now you are moving the graph, including their connections, but a lot of important information is still kept in the node link component which isn’t where it is expected to be.
Try to go through all NodeLink2 components and apply the same transformation to them.

They both have node links though, just a duplicate of the same room with node links in them, so do I need to move the original ones? Those won’t exist when I procedurally generated these rooms either so I don’t think it’s a solution.

I did think maybe the node links aren’t connected in the new room but when I removed them, it caused errors looking for them so they must be recognizing and using them when they are in place.

I fixed it.

If anyone is wondering, I relocated recast first, then relocated point graph after. I guess order matters. Also, to get it work properly in a procedural dungeon I had to load the cache in Start instead of Awake.