Unity 2019.1.3 - Default constructor not found for type Pathfinding.GridGraph

Hey!
First, I’m a long time fan and a user of this framework. I love it!
But I’m compiling a webGL version of my new project and suddenly I’m encountering a new bug…

This happens when a built project is run in a browser. Just when it’s loaded, on start.

Caught exception while deserializing data. System.MissingMethodException: Default constructor not found for type Pathfinding.GridGraph at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0 at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0 at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 at System.Activator.CreateInstance (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.CreateGraph (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.Serialization.AstarSerializer.DeserializeGraph (System.Int32 zipIndex, System.Int32 graphIndex, System.Type[] availableGraphTypes) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.Serialization.AstarSerializer.DeserializeGraphs (System.Type[] availableGraphTypes) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.DeserializeGraphsAdditive (System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.DeserializeGraphs (System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.DeserializeGraphs () [0x00000] in <00000000000000000000000000000000>:0 at Pathfinding.AstarData.Awake () [0x00000] in <00000000000000000000000000000000>:0 at AstarPath.InitializeAstarData () [0x00000] in <00000000000000000000000000000000>:0 at AstarPath.Awake () [0x00000] in <00000000000000000000000000000000>:0 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object) UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:LogError(Object) Pathfinding.AstarData:DeserializeGraphsAdditive(Byte[]) Pathfinding.AstarData:DeserializeGraphs(Byte[]) Pathfinding.AstarData:DeserializeGraphs() Pathfinding.AstarData:Awake() AstarPath:InitializeAstarData() AstarPath:Awake() (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 48)

My first instinct was to add the link.xml file that you mentioned in the tutorial to the assets folder. I’ve also added that FAST_NOEXCEPTIONS definition in JsonSerializer and AstarData just in case. But it’s not working…

I’ve tried disabling Strip Engine Code in Player settings. It seems to be the only solution, but the project size suffers a lot…

Edit - a debug webgl build runs okay, no errors on Strip Engine Code and Stripping Level Low. However, building a not-development build seems to mess that up?

Edit 2- seems like WebAssembly Streaming option in Player settings was causing a problem for some strange reason…

Edit3- I wish building these projects took less time, but here we are. The optimal Player settings for webGL un Unity with A* is Strip Engine Code On, Stripping Level Low and WebAssembly Streaming turned off!

This was a nice case of rubber duck testing :smiley:

Hmm… How annoying…
I wonder. Do you think you could test one thing for me?

Go back to your original settings, but in a new MonoBehavior add

using Pathfinding;
using UnityEngine;

class Blah : MonoBehaviour {
    void Start () {
        var x = new GridGraph();
    }
}

and try if that builds. You don’t have to actually use the MonoBehavior anywhere though.

that script let me turn Stripping Level to High, however WebAssembly Streaming still had to be turned off. :frowning:

Okay. I’ll try to add some code so that stripping level can be set to high at least. I’m not really sure how to make it possible to use webassembly streaming though :/.

Yes, I think it will be fixed somewhat on Unity’s side?
Because my problem with webassembly is that it works while it’s a Development build, but on production build (with the checkbox unticked) it produces an error…

Anyway, for my usage, it’s not a problem, but here’s the log I got:

You can reduce your startup time if you configure your web server to host .unityweb files using brotli compression. [UnityLoader.js:3:8488](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

wasm streaming compile failed: CompileError: wasm validation error: at offset 4: failed to match magic number [UnityLoader.js:4:11163](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

falling back to ArrayBuffer instantiation [UnityLoader.js:4:11163](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

failed to asynchronously prepare wasm: CompileError: wasm validation error: at offset 4: failed to match magic number [UnityLoader.js:4:11163](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

CompileError: “wasm validation error: at offset 4: failed to match magic number” [UnityLoader.js:4:11126](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

CompileError: “wasm validation error: at offset 4: failed to match magic number” [UnityLoader.js:4:11163](file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js)

uncaught exception: abort({}) at jsStackTrace@blob:null/ddf610e9-aba7-4153-99a7-184a214bf979:8:22472 stackTrace@blob:null/ddf610e9-aba7-4153-99a7-184a214bf979:8:22643 onAbort@file:///C:/Users/Arek/Desktop/54/Build/UnityLoader.js:4:11065 abort@blob:null/ddf610e9-aba7-4153-99a7-184a214bf979:8:493622 instantiateArrayBuffer/<@blob:null/ddf610e9-aba7-4153-99a7-184a214bf979:8:31493

That does indeed look like a Unity bug from what I can tell.

Hi! We are having the same issue using Stripping Assemblies: High. We have tried to update but we have seen you are working in the 4.3 beta version.
We have the PRO version.

  • We have moved the link.xml to the Assets folder (despite it should work in any directory)
  • We have set ASTAR_FAST_NO_EXCEPTIONS

Probably are we missing some detail in the docs?

Thanks you in advance

Caught exception while deserializing data.
System.MissingMethodException: Default constructor not found for type Pathfinding.RecastGraph
at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.AstarData.CreateGraph (System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.Serialization.AstarSerializer.DeserializeGraph (System.Int32 zipIndex, System.Int32 graphIndex, System.Type[] availableGraphTypes) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.Serialization.AstarSerializer.DeserializeGraphs (System.Type[] availableGraphTypes) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.AstarData.DeserializeGraphsPartAdditive (Pathfinding.Serialization.AstarSerializer sr) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.AstarData.DeserializeGraphsAdditive (System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0 
at Pathfinding.AstarData.DeserializeGraphs (System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0 
at AstarPath.InitializeAstarData () [0x00000] in <00000000000000000000000000000000>:0 
at AstarPath.Awake () [0x00000] in <00000000000000000000000000000000>:0

Hi

In the current beta version I have added some attributes to the graphs so that they will not be stripped out. You could try the beta and see if it works?

Essentially it only involves adding this attribute to all graph types:

/** Prevents code stripping. \see https://docs.unity3d.com/Manual/ManagedCodeStripping.html */
public class PreserveAttribute : System.Attribute {
}