From fd518ae15509610cb92231ccafcb96b06e030517 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:57:44 +0200 Subject: [PATCH 1/9] Implement ResetStaticFields method for instance cleanup 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> --- sdks/csharp/src/SpacetimeDBNetworkManager.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdks/csharp/src/SpacetimeDBNetworkManager.cs b/sdks/csharp/src/SpacetimeDBNetworkManager.cs index 379bf63d86b..5fa50211481 100644 --- a/sdks/csharp/src/SpacetimeDBNetworkManager.cs +++ b/sdks/csharp/src/SpacetimeDBNetworkManager.cs @@ -12,6 +12,21 @@ public class SpacetimeDBNetworkManager : MonoBehaviour { internal static SpacetimeDBNetworkManager? _instance; + /// + /// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active. + /// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity. + /// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+ + /// + /// + /// See the Unity Domain Reloading Manual + /// and the RuntimeInitializeOnLoadMethodAttribute API Docs for details. + /// + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + private static void ResetStaticFields() + { + _instance = null; + } + public void Awake() { // Ensure that users don't create several SpacetimeDBNetworkManager instances. From 1e7d0137e89e1a4fbd5456b88e7019d4709dcf5a Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:59:23 +0200 Subject: [PATCH 2/9] Implement ResetStaticFields for Log class Added ResetStaticFields method to Log class for static instance reset. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/ISpacetimeDBLogger.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdks/csharp/src/ISpacetimeDBLogger.cs b/sdks/csharp/src/ISpacetimeDBLogger.cs index 7678a03265b..93af53baa88 100644 --- a/sdks/csharp/src/ISpacetimeDBLogger.cs +++ b/sdks/csharp/src/ISpacetimeDBLogger.cs @@ -25,6 +25,21 @@ public static class Log new ConsoleLogger(); #endif + /// + /// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active. + /// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity. + /// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+ + /// + /// + /// See the Unity Domain Reloading Manual + /// and the RuntimeInitializeOnLoadMethodAttribute API Docs for details. + /// + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + private static void ResetStaticFields() + { + Current = null; + } + public static void Debug(string message) => Current.Debug(message); public static void Trace(string message) => Current.Trace(message); public static void Info(string message) => Current.Info(message); From fae1093127fc8642b06956ba80c10f85bda8cf98 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:59:39 +0200 Subject: [PATCH 3/9] Update ISpacetimeDBLogger.cs Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/ISpacetimeDBLogger.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/sdks/csharp/src/ISpacetimeDBLogger.cs b/sdks/csharp/src/ISpacetimeDBLogger.cs index 93af53baa88..1b451d1a4bd 100644 --- a/sdks/csharp/src/ISpacetimeDBLogger.cs +++ b/sdks/csharp/src/ISpacetimeDBLogger.cs @@ -1,4 +1,5 @@ using System; +using UnityEngine; namespace SpacetimeDB { From 07f0e54dbf6b5c59283f95b0f65731749841e9d4 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Wed, 15 Jul 2026 22:01:18 +0200 Subject: [PATCH 4/9] Implement ResetStaticFields for Unity compatibility Added a method to reset static fields to prevent data persistence in Unity. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/Table.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdks/csharp/src/Table.cs b/sdks/csharp/src/Table.cs index 609444815d5..d240e07c7a1 100644 --- a/sdks/csharp/src/Table.cs +++ b/sdks/csharp/src/Table.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using UnityEngine; using SpacetimeDB.BSATN; using SpacetimeDB.ClientApi; using SpacetimeDB.EventHandling; @@ -242,6 +243,21 @@ private static IReadWrite Serializer } } + /// + /// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active. + /// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity. + /// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+ + /// + /// + /// See the Unity Domain Reloading Manual + /// and the RuntimeInitializeOnLoadMethodAttribute API Docs for details. + /// + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + private static void ResetStaticFields() + { + _serializer = null; + } + // The function to use for decoding a type value. Row DecodeValue(BinaryReader reader) => Serializer.Read(reader); From b5c7aaacc75afd5a03415ea077309e80d12b7dd0 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Wed, 15 Jul 2026 22:03:10 +0200 Subject: [PATCH 5/9] Implement ResetStaticFields for Unity play mode Added ResetStaticFields method to prevent data persistence in Unity. Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/SpacetimeDBClient.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdks/csharp/src/SpacetimeDBClient.cs b/sdks/csharp/src/SpacetimeDBClient.cs index ef202ed168b..7c03ea3922b 100644 --- a/sdks/csharp/src/SpacetimeDBClient.cs +++ b/sdks/csharp/src/SpacetimeDBClient.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using UnityEngine; using SpacetimeDB.BSATN; using SpacetimeDB.ClientApi; using Thread = System.Threading.Thread; @@ -289,6 +290,21 @@ internal struct ParsedMessage private static readonly Status Committed = new Status.Committed(default); + /// + /// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active. + /// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity. + /// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+ + /// + /// + /// See the Unity Domain Reloading Manual + /// and the RuntimeInitializeOnLoadMethodAttribute API Docs for details. + /// + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + private static void ResetStaticFields() + { + IsTesting = false; + } + /// /// Get a description of a message suitable for storing in the tracker metadata. /// From 91a4a6968a4b1fac152c931dfee0fc3b80934698 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Sat, 18 Jul 2026 01:44:26 +0200 Subject: [PATCH 6/9] Update sdks/csharp/src/ISpacetimeDBLogger.cs Co-authored-by: Ryan Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/ISpacetimeDBLogger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdks/csharp/src/ISpacetimeDBLogger.cs b/sdks/csharp/src/ISpacetimeDBLogger.cs index 1b451d1a4bd..00d74d5ee47 100644 --- a/sdks/csharp/src/ISpacetimeDBLogger.cs +++ b/sdks/csharp/src/ISpacetimeDBLogger.cs @@ -38,7 +38,7 @@ public static class Log [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] private static void ResetStaticFields() { - Current = null; + Current = new UnityDebugLogger(); } public static void Debug(string message) => Current.Debug(message); From 2dfcd6cbf8771ca51f040ad223682580083e1add Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Sat, 18 Jul 2026 18:57:37 +0200 Subject: [PATCH 7/9] Wrapped unity using in the C# preprocessor Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/SpacetimeDBClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdks/csharp/src/SpacetimeDBClient.cs b/sdks/csharp/src/SpacetimeDBClient.cs index 7c03ea3922b..3b44aed478d 100644 --- a/sdks/csharp/src/SpacetimeDBClient.cs +++ b/sdks/csharp/src/SpacetimeDBClient.cs @@ -6,7 +6,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +#if UNITY_5_3_OR_NEWER using UnityEngine; +#endif using SpacetimeDB.BSATN; using SpacetimeDB.ClientApi; using Thread = System.Threading.Thread; From c1488d9763fae2d3d705505cccc9177ce1cf98e0 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Sat, 18 Jul 2026 18:58:02 +0200 Subject: [PATCH 8/9] Wrapped unity using in the C# preprocessor Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/Table.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdks/csharp/src/Table.cs b/sdks/csharp/src/Table.cs index d240e07c7a1..c164b8ff985 100644 --- a/sdks/csharp/src/Table.cs +++ b/sdks/csharp/src/Table.cs @@ -4,7 +4,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +#if UNITY_5_3_OR_NEWER using UnityEngine; +#endif using SpacetimeDB.BSATN; using SpacetimeDB.ClientApi; using SpacetimeDB.EventHandling; From 2abb740df809afa71c2753505845f1dd35fc68f6 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Sat, 18 Jul 2026 18:58:25 +0200 Subject: [PATCH 9/9] Wrapped unity using in the C# preprocessor Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/ISpacetimeDBLogger.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdks/csharp/src/ISpacetimeDBLogger.cs b/sdks/csharp/src/ISpacetimeDBLogger.cs index 00d74d5ee47..8ec7c265f96 100644 --- a/sdks/csharp/src/ISpacetimeDBLogger.cs +++ b/sdks/csharp/src/ISpacetimeDBLogger.cs @@ -1,5 +1,7 @@ using System; +#if UNITY_5_3_OR_NEWER using UnityEngine; +#endif namespace SpacetimeDB {