Skip to content

Fix SingularGlobalProperty silently failing serialization depending o…#39

Open
renatoaf wants to merge 1 commit intosingular-labs:mainfrom
renatoaf:fix/struct-strip
Open

Fix SingularGlobalProperty silently failing serialization depending o…#39
renatoaf wants to merge 1 commit intosingular-labs:mainfrom
renatoaf:fix/struct-strip

Conversation

@renatoaf
Copy link

@renatoaf renatoaf commented Jan 27, 2026

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.

@MaxEliezerSingular
Copy link

Hi @renatoaf

Thank you for the detailed PR and for explaining the root cause regarding Unity’s code stripping.
Moving this fix into the SDK is definitely the right approach compared to the assembly workaround.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants