How to serialize Tiled Recast graphs?

I’m trying to serialize multiple Tiled Recast graphs into a single byte[]

My code to serialize:

Pathfinding.Serialization.SerializeSettings settings = Pathfinding.Serialization.SerializeSettings.All;

var sr = new Pathfinding.Serialization.AstarSerializer(AstarPath.active.astarData, settings);
sr.OpenSerialize();
sr.SerializeGraphs(ourGraphs.ToArray());
sr.SerializeNodes();
sr.SerializeExtraInfo();
navmeshBytes = sr.CloseSerialize();

To deserialize i just call this:

AstarData.active.astarData.DeserializeGraphsAdditive(navmeshBytes);

The problem is I get an error

Caught exception while deserializing data.
System.Exception: Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?
bd54c2d975c4790e-a0774d0cf5bac563 != 3f73dce26fca9fef-07d0826595762597
at Pathfinding.Serialization.AstarSerializer.DeserializeGraphs () [0x00118] in JsonSerializer.cs:648
at Pathfinding.AstarData.DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) [0x0002f] in AstarData.cs:362

Am I using the serialize functions correctly? Is there a simpler way? can I just save the recasts as meshes, then use TileHandler.RegisterTileType (Mesh source)?

Originally my game had the entire world covered in Tiled Recasts. You helped me a lot and I got it working by using the TileHandler. Unfortunately I need really high resolution (0.1 cell size!) to navigate small corridors in houses. It’s too much data to cover the world, so I am just covering cities areas with high-res Tiled Recasts.

Thanks so much for your help!
-Mark

Hi

What version are you using?
Also, do you think you could send me the saved graph data?

I’m using 3.7.5 pro beta. You can grab the .bytes file here

I also added a pic with some more explanation on what I am trying to do:
screenshot

Thanks for taking a look at this

Hi

I cannot replicate the error, for me it loads just fine.
Would it be possible for you to share the project with me (or just a small example scene in which the error still happens)?

I sent you a PM with a link to my project.
If I serialize and deserialze all Astar.active.graphs it works.
If I serialize only 1 or 2 graphs it seems to have problems with the zip entry upon deserialization. It gives me the “Guid in graph file not equal to guid defined in meta file” warning and stops trying to deserialize

Hey

I think I fixed it.
There was some old code left which implicitly assumed that you were calling SerializeGraphs with the AstarData.graphs array. I have fixed that now (and also cleaned up the code a bit). Also, you can apply the prefab changes with your editor script using some Unity editor API to avoid having to apply each prefab manually (I missed that step first and was confused when my fix didn’t seem to do anything).

Just replace your JsonSerializer.cs file with this paste: http://pastebin.com/LxzGT11A

Yup you fixed it. Thanks so much!

1 Like