-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema-derived types will have their default constructors stripped by Unity's Managed code stripping setting medium or above #135
Comments
thanks for the heads up! |
Thanks for the heads up @tonygiang! (I'm just documenting here my findings for future reference, as this issue is not super high priority) I've tried to configure Managed Code Stripping right now and couldn't make it work for both "Medium" and "High", even if using Maybe using a link.xml file could be easier to configure. Possible solutions could be:
Cheers! |
I just encountered this issue out of nowhere but with code stripping set to Low. Now it seems like the only safe choice is no code stripping. Edit: nope, disabling code stripping doesn't work either. Something else is causing the issue and I can't tell what. I'm starting to think you need to reconsider the reflection approach to schema checking. |
Apparently IronSource SDK could cause problem with Schema types' constructors being stripped as well. I don't know how but it does. |
Hi @endel,
|
Hi @burhanyilmaz, which level of Code Stripping are you using? Low, Medium, or High? |
@endel Thanks for the response! |
I tried these. But I am not sure that these are correct or not :/ MyState.cs //
// THIS FILE HAS BEEN GENERATED AUTOMATICALLY
// DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING
//
// GENERATED USING @colyseus/schema 1.0.25
//
using UnityEngine.Scripting;
using Colyseus.Schema;
[Preserve]
public partial class MyState : Schema
{
[Preserve]
[Type(0, "string")]
public string currentTurn = "";
} link.xml <linker>
<assembly fullname="Colyseus">
<type fullname="Colyseus.Schema.ReflectionType" preserve="all"/>
</assembly>
</linker> Thanks! |
When the target platform is macOS, there is no problem. I connected to the room and received messages. |
@endel @tonygiang |
Not so fast. This issue affects all C# types generated by |
Relevant to this discussion, a Discord user has reported this comment: (building for Android)
|
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 toMissingMethodException
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 asColyseus.Schema.ReflectionField
,Colyseus.Schema.ReflectionType
andColyseus.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.The text was updated successfully, but these errors were encountered: