Schema-derived types will have their default constructors stripped by Unity's Managed code stripping setting medium or above
See original GitHub issueUnity has a feature called managed code stripping to reduce the size of a build. During this process, if the setting is set to Medium or High, all types derived from Colyseus.Schema.Schema
will have their default constructors stripped because Unity’s linker determine that they are unreachable code, which leads to MissingMethodException
during runtime handshaking.
Schema-derived types include all types generated by schema-codegen
and also the built-in types used by Colyseus Unity client such as Colyseus.Schema.ReflectionField
, Colyseus.Schema.ReflectionType
and Colyseus.Schema.Reflection
.
While adding the UnityEngine.Scripting.Preserve
attribute to each Schema-derived types will preserve their default constructors, it will lead to a “Local schema mismatch from server” exception on High managed code stripping setting, which technically is a different issue from this, but until there is an official fix, the safe option for users of Colyseus Unity client for now is to build with managed code stripping setting set to Low or disabled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (8 by maintainers)
Top GitHub Comments
Not so fast. This issue affects all C# types generated by
schema-codegen
. It will be fixed whenschema-codegen
is fixed.Relevant to this discussion, a Discord user has reported this comment: (building for Android)