Custom graph get a deserialize error in web build but not OSX build

When I switch to Web build from stand-alone (MacOS) I get a cannot deserialize data error.
Also my custom graph “PathGraph2D” no longer shows up in the AstarPath inspector under add new graphs. If I switch the platform back to MacOS, “PathGraph2D” reappears as an option in the AstarPath inspector.

A* 5.3.3

System.Exception: Caught exception while deserializing data. ---> System.Exception: No graph of type 'PathGraph2D' could be created, type does not exist
  at Pathfinding.Serialization.GraphMeta.GetGraphType (System.Int32 index, System.Type[] availableGraphTypes) [0x00042] in ./Packages/com.arongranberg.astar/Core/Serialization/JsonSerializer.cs:960 
  at Pathfinding.Serialization.AstarSerializer.DeserializeGraph (System.Int32 zipIndex, System.Int32 graphIndex, System.Type[] availableGraphTypes) [0x00000] in ./Packages/com.arongranberg.astar/Core/Serialization/JsonSerializer.cs:588 
  at Pathfinding.Serialization.AstarSerializer.DeserializeGraphs (System.Type[] availableGraphTypes, System.Boolean allowLoadingNodes) [0x00023] in ./Packages/com.arongranberg.astar/Core/Serialization/JsonSerializer.cs:624 
  at Pathfinding.AstarData.DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) [0x00072] in ./Packages/com.arongranberg.astar/Core/AstarData.cs:439 
  at Pathfinding.AstarData.DeserializeGraphsAdditive (System.Byte[] bytes) [0x00033] in ./Packages/com.arongranberg.astar/Core/AstarData.cs:400 
   --- End of inner exception stack trace ---
UnityEngine.Debug:LogError (object)
Pathfinding.AstarData:DeserializeGraphsAdditive (byte[]) (at ./Packages/com.arongranberg.astar/Core/AstarData.cs:412)
Pathfinding.AstarData:DeserializeGraphs (byte[]) (at ./Packages/com.arongranberg.astar/Core/AstarData.cs:380)
Pathfinding.AstarData:DeserializeGraphs () (at ./Packages/com.arongranberg.astar/Core/AstarData.cs:315)
Pathfinding.AstarData:OnEnable () (at ./Packages/com.arongranberg.astar/Core/AstarData.cs:161)
AstarPath:OnEnable () (at ./Packages/com.arongranberg.astar/Core/AstarPath.cs:1287)

I’ll have to see what @aron_granberg says about this but in the meantime can you post your custom graph’s script somewhere that we can review it?

Custom graph example

using Pathfinding;
public class CustomGraph : PointGraph {}

editor example in an editor folder

using Pathfinding;

[CustomGraphEditor(typeof(CustomGraph), "CustomGraph")]
public class CustomGraphEditor : GraphEditor {
    // Here goes the GUI
    public override void OnInspectorGUI (NavGraph aTarget) {
        
    }
}

In standalone (MacOs) I can add a CustomGraph in the Inspector to an AstarPath GameObject.
When I switch to Web build, I get the error in the previous msg if I have added the CustomGraph, there is no error if I have not added the CustomGraph. Either way, Custom Graph does not appear in the list of graph types to add in the Inspect in Web mode, but does appear in MacOs mode.

Hi

WebGL unfortunately doesn’t support reflection well, so the graph type cannot be discovered dynamically. But I think Unity might have improved this in recent versions.

Could you try something for me, in the AstarData.cs script, remove replace all mentions of UNITY_WEBGL with FALSE. and see if a build works.

You’ll need to annotate your graph type like this, to ensure it is not stripped from the build:

[Pathfinding.Util.Preserve]
public class CustomGraph : PointGraph {}
1 Like

Thanks that worked.