A* and Mirror Networking Obstacle Problem

Hello, I have an online game and I use mirror networking. I have 20 maps in total and I keep the maps as gameobjects. Their children also have obstacles and NPCs. There are NPCs on every map and they move. My problem is that the SERVER determines the position where the NPCs will move. However, since the setactive of all maps and obstacles on the server is true, when I use Scan(), it takes the obstacles of all maps. What I want is for the server to detect only the obstacles on the map where the NPC is located. Is this possible? And there are so many npcs, I don’t think it’s possible to use Scan() for each of their movements.

For starters, if you’re not already splitting the 20 maps into different graphs, that might be a good route to explore. That way you can only update or scan maps that are in active use or view by a player. That way you can specify what graphs and therefore maps you want scanned with AstarPath.Scan(graphToScan), specifying which graphs you want updated.

…Actually, after writing that I’m realizing I’m not sure where the issue is you’re having- is the server having a hard time scanning all 20 graphs with all obstacles? Is this a performance issue, or is it causing some other issue with your development? Original post only says the “problem is that the SERVER determines the position where the NPCs will move”. Let us know what the effect of having the server run the Scan() is having on your project and I can give a better solution :saluting_face::saluting_face:

I’m guessing that the issue is that all the maps overlap in space. So whenever one graph is scanned, it will use the objects from all the overlapping maps.

I’d recommend moving the maps so that they do not overlap.
You can also place them in different layers and make the graph only use the layer appropriate for the corresponding map.

Yes, all the maps overlap. I do not experience performance problems. I want the maps to detect their own obstacles, but they detect all obstacles. I cannot separate the maps from each other because I will have to create 20 grids, which will cause performance problems.

Why would you need to create 20 grids? can’t you just modify the grids values to fit to the size of each of the maps and set its center to match the location of the next map and scan it then? It shouldn’t be detecting all obstacles if you only enable which ones you want scanned into the graph but it would probably be better all together if u just need one map instance running to realign the graph with it

Unfortunately I cant do that because all maps you should be active. And all maps have npcs.

What kind of graph type are you using? it sounds like Layered Grid Graph seems like the best approach for you here from sounds of it

I am using Isometric grid graph but adding 20 grids fixed my problem. Is there any way to scan grids more optimized? I am using Scan() now

Yes you can scan a graph by bounds that you provide with a simple function like this

public void updateGraph(Vector3 boundsPos, int nodesAmountX = 1, int nodesAmountY = 1)
{
    Bounds myBounds = new Bounds();
    myBounds.center = boundsPos;
    myBounds.extents = new Vector3(nodesAmountX, nodesAmountY, 0);
    guo = new GraphUpdateObject(myBounds);
    // Set some settings
    guo.updatePhysics = true;
    AstarPath.active.UpdateGraphs(guo);
}

okay thank you!