Fix SingularGlobalProperty silently failing serialization depending o…#39
Fix SingularGlobalProperty silently failing serialization depending o…#39renatoaf wants to merge 1 commit intosingular-labs:mainfrom
Conversation
…n Uinty stripping settings
|
Hi @renatoaf Thank you for the detailed PR and for explaining the root cause regarding Unity’s code stripping. We are reviewing this now and will work on getting it merged. We really appreciate the high-quality contribution! If you see any other optimization or serialization improvements needed in the Unity SDK, please feel free to share. |
|
Hi @renatoaf We're glad we can now save developers from having to manually preserve the entire assembly. |
Summary
Added [Preserve] attribute to SingularGlobalProperty class to prevent Unity's managed code stripping from removing it during build optimization.
Problem
Unity's static code analysis doesn't detect that SingularGlobalProperty fields are used in JSON serialization via reflection. As a result, Unity's code stripping removes these fields during the build process, causing global properties to serialize as empty objects in the SDK when they're set before lib initialization (and serialized along SingularConfig via
ToJsonString).This issue has affected production releases, where games using the Singular Unity SDK didn't report global properties. We have worked around this by preserving the entire assembly.
<assembly fullname="Singular" preserve="all"/>Solution
Added the [Preserve] attribute to the SingularGlobalProperty class, which explicitly tells Unity's code stripper to preserve this class and its members during optimization. This is the recommended upstream fix that prevents the issue at the SDK level rather than requiring downstream workarounds.