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 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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 09/13] 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 { From ebdeab5f49f4b94eece613e77065735f59c4623c Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:15:42 +0200 Subject: [PATCH 10/13] Fix code included in other than unity 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 8ec7c265f96..c91d1b13d9c 100644 --- a/sdks/csharp/src/ISpacetimeDBLogger.cs +++ b/sdks/csharp/src/ISpacetimeDBLogger.cs @@ -28,6 +28,7 @@ public static class Log new ConsoleLogger(); #endif +#if UNITY_5_3_OR_NEWER /// /// 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. @@ -42,6 +43,7 @@ private static void ResetStaticFields() { Current = new UnityDebugLogger(); } +#endif public static void Debug(string message) => Current.Debug(message); public static void Trace(string message) => Current.Trace(message); From 4023b72311c7b9714c62d53f37a5363c0c6847e3 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:16:47 +0200 Subject: [PATCH 11/13] Fix Unity code inclusion Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/Table.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdks/csharp/src/Table.cs b/sdks/csharp/src/Table.cs index c164b8ff985..27b56df2ecf 100644 --- a/sdks/csharp/src/Table.cs +++ b/sdks/csharp/src/Table.cs @@ -245,6 +245,8 @@ private static IReadWrite Serializer } } + +#if UNITY_5_3_OR_NEWER /// /// 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. @@ -259,6 +261,7 @@ private static void ResetStaticFields() { _serializer = null; } +#endif // The function to use for decoding a type value. Row DecodeValue(BinaryReader reader) => Serializer.Read(reader); From 7e208b77c034f6851ab057bf5b7fb41747695887 Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:17:37 +0200 Subject: [PATCH 12/13] Fix Unity reset event being included 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 3b44aed478d..647f2558496 100644 --- a/sdks/csharp/src/SpacetimeDBClient.cs +++ b/sdks/csharp/src/SpacetimeDBClient.cs @@ -292,6 +292,7 @@ internal struct ParsedMessage private static readonly Status Committed = new Status.Committed(default); +#if UNITY_5_3_OR_NEWER /// /// 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. @@ -306,6 +307,7 @@ private static void ResetStaticFields() { IsTesting = false; } +#endif /// /// Get a description of a message suitable for storing in the tracker metadata. From 8f66010975842b8e327d6c0d1357fa76116eabcf Mon Sep 17 00:00:00 2001 From: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> Date: Mon, 3 Aug 2026 18:18:29 +0200 Subject: [PATCH 13/13] Fully qualified System.Diagnostics.Debug to avoid clash with UnityEngine.Debug Signed-off-by: Vanessa Vinther <7903603+ImDreamerDev@users.noreply.github.com> --- sdks/csharp/src/Table.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdks/csharp/src/Table.cs b/sdks/csharp/src/Table.cs index 609444815d5..5c8abc67944 100644 --- a/sdks/csharp/src/Table.cs +++ b/sdks/csharp/src/Table.cs @@ -431,7 +431,8 @@ protected virtual void InvokeUpdate(IEventContext context, IStructuralReadWrite /// void IRemoteTableHandle.PreApply(IEventContext context, IParsedTableUpdate parsedTableUpdate) { - Debug.Assert(wasInserted.Count == 0 && wasUpdated.Count == 0 && wasRemoved.Count == 0, "Call Apply and PostApply before calling PreApply again"); + // Fully qualified to avoid clash with UnityEngine.Debug + System.Diagnostics.Debug.Assert(wasInserted.Count == 0 && wasUpdated.Count == 0 && wasRemoved.Count == 0, "Call Apply and PostApply before calling PreApply again"); if (IsEventTable) return; // Event tables have no deletes. var delta = (ParsedTableUpdate)parsedTableUpdate; foreach (var (_, value) in Entries.WillRemove(delta.Delta))