Fix SingularGlobalProperty silently failing serialization depending o…#39
Open
renatoaf wants to merge 1 commit intosingular-labs:mainfrom
Open
Fix SingularGlobalProperty silently failing serialization depending o…#39renatoaf wants to merge 1 commit intosingular-labs:mainfrom
renatoaf 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.