Bug - Issues deserializing NodeLink2

Hi Aron.

I’ve recently updated all our codebase with 3.8.5b. We have all our graphs cached, so I didn’t notice this issue popping up until I just made a new graph in our test sandbox. We have a few places where NodeLink2 are used and after creating this new graph, I get this error:

Caught exception while deserializing data.
System.Exception: Tried to deserialize a NodeLink2 reference, but the link could not be found in the scene.
If a NodeLink2 is included in serialized graph data, the same NodeLink2 component must be present in the scene when loading the graph data.
at Pathfinding.NodeLink2.DeserializeReferences (Pathfinding.Serialization.GraphSerializationContext ctx) [0x00137] in C:\Dev\DivideUnity5\Assets\AstarPathfindingProject\Core\Misc\NodeLink2.cs:336
at Pathfinding.Serialization.AstarSerializer.DeserializeNodeLinks (Pathfinding.GraphNode[] int2Node) [0x0002e] in C:\Dev\DivideUnity5\Assets\AstarPathfindingProject\Core\Serialization\JsonSerializer.cs:712
at Pathfinding.Serialization.AstarSerializer.DeserializeExtraInfo () [0x00077] in C:\Dev\DivideUnity5\Assets\AstarPathfindingProject\Core\Serialization\JsonSerializer.cs:701
at Pathfinding.AstarData.DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) [0x00047] in C:\Dev\DivideUnity5\Assets\AstarPathfindingProject\Core\AstarData.cs:333
at Pathfinding.AstarData.DeserializeGraphsAdditive (System.Byte[] bytes) [0x00023] in C:\Dev\DivideUnity5\Assets\AstarPathfindingProject\Core\AstarData.cs:287
Pathfinding.AstarData:DeserializeGraphsAdditive(Byte[]) (at Assets/AstarPathfindingProject/Core/AstarData.cs:298)
Pathfinding.AstarData:DeserializeGraphs(Byte[]) (at Assets/AstarPathfindingProject/Core/AstarData.cs:272)
Pathfinding.AstarData:LoadFromCache() (at Assets/AstarPathfindingProject/Core/AstarData.cs:192)

I read in another thread that you changed the code to allow for serializations of links, but there seems to be an issue. The NodeLink2 objects are in the scene, they are marked as one way, with end transform being set on an empty transform (without a NodeLink2 component, as it is a one way).

I’m not sure why this error happens, or what exactly i’m doing wrong.


Are the exact same NodeLink components present in the scene when caching the graph and loading the graph? Or are you creating them dynamically somehow?

yep the exact same ones are there.

the only thing I can think of is that somehow the order of operation is affecting this, so the graph loads before the rest of the scene loads perhaps?

I ran this with the debugger on, and I’m seeing that the error is thrown since
if (usedIDs.TryGetValue(linkID, out link)) returns false, as the userIDs dictionary doesn’t contain the right UniqueIds. When breakpointing in SerializeReferences, I see the IDs coming from the links, and those are identical to the ones coming in at DeserializeReferences(). However the userIDs dictionary have a different set of IDs.

Another thing, I noticed one of my links gets saved with a UniqueId of 0. Which must be a bug of some un-initialized field.

Do you happen to have a small test project that I could replicate this bug in?

I’ll have to make you a repro project. Currently we are out of office presenting at PSX, so it will have to wait until next week. Where can I upload this to?

For future readers:
Turned out to be a bug in the deserialization code, it didn’t handle some cases where variables could be null.
This has been fixed in my dev version now.

If you are experiencing it and need the fix before the next version is out, edit the following:

in internal static void DeserializeReferences of NodeLink2.cs

if (link2 != null){
reference[startNode] = link2;
reference[endNode] = link2;

if (link2 != null) {
if (startNode != null)
reference[startNode] = link2;
if (endNode != null)
reference[endNode] = link2;