A* Pathfinding Project

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


#1

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:


#2

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.


#3

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


#4

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 :/.


#5

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


#6

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