question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema-derived types will have their default constructors stripped by Unity's Managed code stripping setting medium or above

See original GitHub issue

Unity 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
tonygiangcommented, Jun 22, 2021

Not so fast. This issue affects all C# types generated by schema-codegen. It will be fixed when schema-codegen is fixed.

0reactions
endelcommented, Sep 21, 2022

Relevant to this discussion, a Discord user has reported this comment: (building for Android)

i can’t compile il2cpp because unity only has low striping for il2cpp and not disable… but it works on Mono backend which has the disable function stripping

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managed code stripping
Managed code stripping removes unused code from a build, which can ... with the Preserve attribute preserves both the type and the default...
Read more >
Addressables and Code Stripping (IL2CPP)
ProviderOperation is being stripped due to the use of reflection. Code (CSharp):. MissingMethodException : Default constructor not found for ...
Read more >
Don't ignore the side effect of Managed code stripping
The main purpose of this feature is to reduce the size of the app by removing some unused code.
Read more >
How can I prevent a pre-built assembly in my Unity ...
I've run into a problem where il2cpp is stripping the constructors of these models, because they're only invoked via reflection. I don't seem...
Read more >
MRTK and managed code stripping — MRTK2
When using Unity's IL2CPP scripting backend (optional in Unity 2018.4, required in 2019 and newer), managed code stripping occurs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found