LayerGridGraph: NullReferenceException when caching

Every time I try to generate cache for LayerGridGraph (I am using the Inspector menu), I get this error

NullReferenceException: Object reference not set to an instance of an object Pathfinding.Serialization.AstarSerializer.SerializeNodeConnections (Int32 index) (at Assets/AstarPathfindingProject/Core/Serialization/JsonSerializer.cs:279) Pathfinding.Serialization.AstarSerializer.SerializeNodes () (at Assets/AstarPathfindingProject/Core/Serialization/JsonSerializer.cs:191) Pathfinding.AstarData.SerializeGraphsPart (Pathfinding.Serialization.AstarSerializer sr) (at Assets/AstarPathfindingProject/Core/AstarData.cs:283) Pathfinding.AstarData.SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, System.UInt32& checksum) (at Assets/AstarPathfindingProject/Core/AstarData.cs:267) Pathfinding.AstarData.SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings) (at Assets/AstarPathfindingProject/Core/AstarData.cs:257) Pathfinding.AstarData.SaveCacheData (Pathfinding.Serialization.SerializeSettings settings) (at Assets/AstarPathfindingProject/Core/AstarData.cs:241) AstarPathEditor.DrawSerializationSettings () (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:1544) AstarPathEditor.DrawMainArea () (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:822) AstarPathEditor.OnInspectorGUI () (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:426) UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:888) UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:243) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

It seems like this bug was fixed in 3.2.5, and it actually works fine for GridGraph and LayerGridGraph with only 1 layer. However, in case LayerGridGraph spans multiple floors, that exception still occurs.
Is there any quick workaround for that? Everything is perfect except this caching issue…

Thanks for help.

I have same issue with Recast Graph. It works for GridGraph too.
Pretty annoying as Recast graph are quite slow to compute.

It seems I was able to patch this issue by adding:

if(graphs[i] == null) continue;

to lines 183, 191 and 246 in JsonSerializer.cs.

Hopefully this may help someone else.

Thanks cavila, but that still doesn’t works for me. It fails even on the included demo scene… If I also modify line 280 to:

if (node == null || node.connections == null) { writer.Write((ushort)0); continue; }

then it does saves the data, but fails to load it with a message:
“Node data did not match with bounds data. Probably a change to the bounds/width/depth data was made after scanning the graph just prior to saving it. Nodes will be discarded”