Help needed with removing graphs

I need some help!

Some context: we store maps on steam workshop in external files, including the serialized graphs.

We use 4 overlapping recast graphs for units of different sizes and stances. This works well enough with some custom classes ( tilehandlerhelper, links ) that apply updates and links to each navmesh and not just the first one, though there are some odd bugs.

Now requirements changed and I want to change to how it’s supposed to be, just one navmesh graph. The problem is I need to keep the maps functional without re-scanning, as that’s not possible.

I saw in the code comments that back before 3.2.5 the graphs would get “properly” removed and the graph indices updated. Could you dig up and share that old code?

In the current version the “empty slots” are kept and re-used on the next scan, which then completely messes up my setup, moving the point graph from index 4 to index 0, but it doesn’t copy the settings.

Alternatively, how can I manually update the graph indices after re-organizing the graphs array?

Hi

How exactly are you doing things. Are you loading graphs from a file? Or are you removing/adding graphs during runtime?

I use AstarPath.active.astarData.DeserializeGraphs(bytes) to load the navigation data from the external file after loading the scene with the empty A* setup in it (graphs setup but not scanned).

Oh, I forgot to specify that the comment about 3.2.5 was on
RemoveGraph() in AstarData.cs

Ok. DeserializeGraphs should remove all existing graphs and add the new graphs at index 0, 1, 2, etc. So this is not what you want to do?

No. After deserializing the old maps, I want to remove the now obsolete graphs at index 0, 2, 3, and move the now sole navmesh graph from index 1 to 0, and the move point graph from index 4 to 1.

I wouldn’t even mind if the deleted graphs forever remained null, but at the next scan it gets completely broken as the point graph gets moved to index 0 without its settings.

Ah. Okay. I think the easiest way is to serialize them to a byte array again after you have removed them and then deserialize them again.

AstarPath.active.data.RemoveGraph(...);
AstarPath.active.data.DeserializeGraphs(AstarPath.active.data.SerializeGraphs());

Loaded graphs cannot change their graph indices because any nodes that they have created rely on the graph indices staying the same.

Actually, never mind the thing about scan, I was accidentally removing the point graph so scan would make a new one for the links. Otherwise the graphs remain null-ed out at their original indexes.

Ok, I managed to re-assign the point graph to index 0 without anything breaking, keep the recast on index 1, and deleted the other graphs. Consider this issue closed.

Btw, I did try to “AstarPath.active.data.DeserializeGraphs(AstarPath.active.data.SerializeGraphs());”
but that just cleared out the graph completely.

Also, I would appreciate if you could take a look at my bugreport on navmeshcuts, that’s a pretty bad one.

Huh, that’s strange. I’ll have to test that.