JsonSerializationException when receiving a message from server in WebGL export
See original GitHub issueWhen exporting my Unity project as a WebGL application, the following exception is thrown during runtime:
JsonSerializationException: Unable to deserialize instance of MyMessage because there is no parameterless constructor is defined on type.
This prevents any data sent by the server through messages to be deserialized and used on the client, which is a major problem.
After investigating on the issue with my local fork, I found that it originates from the TryGetConstructor
method, at line 200:
if (AotRuntime || type.IsAbstract || type.IsInterface)
return false;
It seems that AotRuntime
is set to true for WebGL and iOS platforms, as shown in line 43 of the same file.
#if ((UNITY_WEBGL || UNITY_IOS || ENABLE_IL2CPP) && !UNITY_EDITOR)
AotRuntime = true;
#else
I don’t really know what this parameter corresponds to, but it seems to cause the issue I describe here. My quick and dirty fix was to comment the AotRuntime
part of the condition at line 200, but I can’t tell if it was there for a reason in the first place. What should be done to fix this?
Issue Analytics
- State:
- Created a year ago
- Comments:14 (5 by maintainers)
Top GitHub Comments
Yep it is a bug,
AotRuntime
check should be few lines down. I will make PR.Thanks to @deniszykov’s PR (https://github.com/colyseus/colyseus-unity-sdk/pull/210) this has been finally fixed on latest version (0.14.21)