Node Issue and Random Generated Map

Hello i have two questions,
First one is my Nodes always including neighbor nodes.

Second problem is I have a random generated map so it’s size is always changing. If I use bigger size for pathfinding it causes perfomance issues. How can I prevent to exceeding pathfinding limits. Thanks!

Hi,
From the second screenshot it looks like there is never a connection from one room to the next. Only the player can transition to another room.
It’s perfectly fine to create a grid graph per room.
Only generate the new rooms being. You could even say that there is only 1 navmesh the size of one room, when the player transitions to another room it snaps back to the center of the ‘current room’ and rescan.

I don’t fully understand what your first problem is.

Thank you for replying! My first problem is when I create an object (stone, wall) it blocks more than one block, it blocks closest blocks too. When I put one rock in the picture it included blocks in front, behind, right and left

For the second one how can I create graphs, should I create a pathfinder script for each room? In the script it says that not use more than one pathfinder. So which script should I add to my room?

To fix this you probably want to slightly decrease the collision testing diameter, something like 0.9f
However this might result in the edges of the room to become walk able, to fix that you can use erosion

You don’t need to add a script, you want to create a new Grid Graph on the A* Object every time a new room is created. And calculate that graph.

1 Like

Which function should I call to create a new Grid Graph in script,

this one right?
https://arongranberg.com/astar/documentation/dev_4_3_8_84e2f938/old/runtime-graphs.php

Hey I finally manage to create graph now I have only one problem. How can I set true 2D option and change Obstacle Layer Mask?

I solved my problem thanks to posts that posted years ago. I put my code here in case someone stays in the same situation as me

// This holds all graph data
AstarData data = AstarPath.active.data;
// This creates a Grid Graph
GridGraph gg = data.AddGraph(typeof(GridGraph)) as GridGraph;
gg.collision.use2D = true;
gg.collision.diameter = 1.4f;
//it's necessary for 2D bool check
gg.rotation.x = -90.0f;

// Setup a grid graph with some values
int width = 16;
int depth = 8;
float nodeSize = 1f;
// Set your room position
gg.center = new Vector3(roomPosition.x, roomPosition.y, 0f);
//Add your masks here
gg.collision.mask = LayerMask.GetMask("Wall","Obstacles");

// Updates internal size from the above values
gg.SetDimensions(width, depth, nodeSize);
1 Like