Implement ResetStaticFields method for Unity instance cleanup#5554
Open
ImDreamerDev wants to merge 10 commits into
Open
Implement ResetStaticFields method for Unity instance cleanup#5554ImDreamerDev wants to merge 10 commits into
ImDreamerDev wants to merge 10 commits into
Conversation
Added a method to reset the static instance to prevent data persistence when entering Play Mode with Domain Reloading disabled. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Added ResetStaticFields method to Log class for static instance reset. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Added a method to reset static fields to prevent data persistence in Unity. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Added ResetStaticFields method to prevent data persistence in Unity. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
rekhoff
reviewed
Jul 17, 2026
rekhoff
left a comment
Contributor
There was a problem hiding this comment.
Thank you for your contribution! A few things I noted when looking over your changes.
Co-authored-by: Ryan <r.ekhoff@clockworklabs.io> Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com>
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.
This PR adds support for Unity projects that have Domain Reloading disabled in Enter Play Mode Options.
Normally, Unity resets static fields when entering Play Mode, but when Domain Reloading is disabled, static data can remain from previous play sessions. This can cause unexpected behavior, such as old singleton instances, cached data, or test states carrying over.
To prevent this, static reset methods have been added to a few core SDK classes. These methods are called automatically by Unity when the subsystem is initialized, ensuring the SDK starts from a clean state each time.
Changes made:
Logto clear the current logger instance.SpacetimeDBNetworkManagerto clear the singleton instance.RemoteTableHandleBaseto clear the cached serializer instance.DbConnectionBaseto reset the testing flag.RuntimeInitializeOnLoadMethod.These changes should make the SDK more reliable when used in Unity projects that disable Domain Reloading, without affecting normal Unity projects that keep it enabled.
API and ABI breaking changes
No API or ABI breaking changes.
This only changes internal static state handling and does not modify existing public APIs or behavior.
Expected complexity level and risk
Complexity: 2/5
This is a relatively small change focused on improving Unity compatibility.
The main consideration is making sure the reset methods run at the correct time during Unity initialization and that clearing static fields does not interfere with normal SDK usage. The changes are isolated to a few classes that manage static state.
Testing
Tested the changes in Unity with Domain Reloading disabled to confirm that static data is properly reset between play sessions.
Verified that:
The SDK initializes correctly after entering Play Mode multiple times.
Singleton instances do not persist unexpectedly.
Cached serializers and test state are cleared correctly.
Existing behavior remains unchanged when Domain Reloading is enabled.
Test normal Unity Play Mode behavior with Domain Reloading enabled.
Test with Unity Enter Play Mode Options with Domain Reloading disabled.