Manually change node positions on Grid Graph


#1

I am currently using your procedural grid mover example and it works great. However, I need a low detail version for terrain in the horizon, but I don’t want to use colliders. I start by creating the grid using normal raycasting so I have something to work with and to make sure it generates properly, then I’m trying to update the node positions without any luck. I am using an older version (3.5.1) with the newest Unity version and haven’t upgraded since I didn’t see anything relevant to my needs. Perhaps that is the issue, since much of the documentation doesn’t seen to work (most of the AddWorkItem examples, besides those in the procedural examples)

Initialization then calling scan to generate graph

        gridGraphLod = data.AddGraph(typeof(GridGraph)) as GridGraph;
        gridGraphLod.center = new Vector3(player.transform.position.x, -100f, player.transform.position.z);       
        
        gridGraphLod.width = pathSize;
        gridGraphLod.depth = pathSize;
        gridGraphLod.nodeSize = 27;
        gridGraphLod.maxClimb = maxClimb;
        gridGraphLod.UpdateSizeFromWidthDepth();
        gridGraphLod.collision.fromHeight = 400;
        gridGraphLod.collision.mask = collisionMask;
        gridGraphLod.maxClimb = 0;
        gridGraphLod.collision.heightMask = heightMask;
        gridGraphLod.collision.unwalkableWhenNoGround = false;

        total = gridGraphLod.width * gridGraphLod.nodeSize;
        gridScale = Vector3.one * total;
        gridBoundsLod.transform.localScale = gridScale;
        gridBoundsLod.transform.position = new Vector3(gridGraphLod.center.x, player.transform.position.y, gridGraphLod.center.z);

Using something like this I can change the walkability and it works fine, but if I do anything with node.position it breaks, well at least it doesn’t show anything in the scene view anymore. Even if I set node.position = node.position it doesn’t seem to work, am I missing something. I am also settting collisionCheck and heightCheck to false since all I want to do is change the positions for now. I don’t want to use any physics calculations on this secondary grid.

var lodGraph = AstarPath.active.astarData.graphs[1] as GridGraph;
lodGraph.collision.collisionCheck = false;  
lodGraph.collision.heightCheck = false;

AstarPath.RegisterSafeUpdate(() => {

                var gg = lodGraph;
                var nodes = lodGraph.nodes;                

                for (int z = 0; z < gg.depth; z++) {
                    for (int x = 0; x < gg.width; x++) {
                        var node = gg.nodes[z * gg.width + x];
                        //node.position = new Int3(-1229434, -100000, -1693870);
                        node.Walkable = Random.value > 0.5f;
                    }
                }

              for (int z = 0; z < gg.depth; z++) {
                   for (int x = 0; x < gg.width; x++) { //assumed not needed, but tried using to no avail
                      //graph.UpdateNodePositionCollision(nodes[z * gg.width + x], x, z, false);
                  }
              }

                for (int z = 0; z < gg.depth; z++) {
                    for (int x = 0; x < gg.width; x++) {
                        graph.CalculateConnections(nodes, x, z, nodes[z * gg.width + x]);  
                    }
                }
                // Refresh internal pathfinding data
                AstarPath.active.FloodFill();
            }, false);

#2

Hi

Oh wow, 3.5.1? That’s over 4 years old. Yeah… there are a ton of things that have changed since then, so the current documentation will not be of much help I’m afraid. You can access older documentation if you click on ‘Show Older Versions’ on the download page (https://www.arongranberg.com/astar/download).


#3

I didn’t realize it was that old, and that I’ve been working on the same project for that long… Ill download the newest version and see how that goes. Thanks for the help.


#4

I update to the newest 4.1.16, and everything looks good so far. The only problem is the Show Graphs button doesn’t seem to work. I’ve played with the various settings and it will debug the generated paths, but not the whole graph like it did in previous version. Is there something I’m missing?


#5

Hi

Perhaps something has gone wrong in the import and some shaders aren’t working. Try to delete the package and re-import it again.