Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd518ae
Implement ResetStaticFields method for instance cleanup
ImDreamerDev Jul 15, 2026
1e7d013
Implement ResetStaticFields for Log class
ImDreamerDev Jul 15, 2026
fae1093
Update ISpacetimeDBLogger.cs
ImDreamerDev Jul 15, 2026
07f0e54
Implement ResetStaticFields for Unity compatibility
ImDreamerDev Jul 15, 2026
b5c7aaa
Implement ResetStaticFields for Unity play mode
ImDreamerDev Jul 15, 2026
91a4a69
Update sdks/csharp/src/ISpacetimeDBLogger.cs
ImDreamerDev Jul 17, 2026
2dfcd6c
Wrapped unity using in the C# preprocessor
ImDreamerDev Jul 18, 2026
c1488d9
Wrapped unity using in the C# preprocessor
ImDreamerDev Jul 18, 2026
2abb740
Wrapped unity using in the C# preprocessor
ImDreamerDev Jul 18, 2026
c245f2a
Merge branch 'master' into master
ImDreamerDev Jul 18, 2026
50c33d2
Merge branch 'master' into master
ImDreamerDev Jul 22, 2026
2375508
Merge branch 'master' into master
ImDreamerDev Jul 24, 2026
ebdeab5
Fix code included in other than unity
ImDreamerDev Jul 27, 2026
4023b72
Fix Unity code inclusion
ImDreamerDev Jul 27, 2026
7e208b7
Fix Unity reset event being included
ImDreamerDev Jul 27, 2026
f149791
Merge branch 'master' into master
ImDreamerDev Jul 28, 2026
b8716b6
Merge branch 'master' into master
ImDreamerDev Jul 29, 2026
8f66010
Fully qualified System.Diagnostics.Debug to avoid clash with UnityEng…
ImDreamerDev Aug 3, 2026
73b995a
Merge branch 'master' into master
ImDreamerDev Aug 3, 2026
c243060
Merge branch 'master' into master
ImDreamerDev Aug 3, 2026
a08e8dd
Merge branch 'master' into patch-1
ImDreamerDev Aug 3, 2026
a5c4b1d
Merge pull request #1 from ImDreamerDev/patch-1
ImDreamerDev Aug 3, 2026
9bfa231
Merge branch 'master' into master
ImDreamerDev Aug 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sdks/csharp/src/ISpacetimeDBLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
Comment thread
ImDreamerDev marked this conversation as resolved.
#endif

namespace SpacetimeDB
{
Expand All @@ -25,6 +28,23 @@ public static class Log
new ConsoleLogger();
#endif

#if UNITY_5_3_OR_NEWER
/// <summary>
/// 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+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
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);
public static void Info(string message) => Current.Info(message);
Expand Down
20 changes: 20 additions & 0 deletions sdks/csharp/src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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;
Expand Down Expand Up @@ -289,6 +292,23 @@ internal struct ParsedMessage

private static readonly Status Committed = new Status.Committed(default);

#if UNITY_5_3_OR_NEWER
/// <summary>
/// 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+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
IsTesting = false;
}
#endif

/// <summary>
/// Get a description of a message suitable for storing in the tracker metadata.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions sdks/csharp/src/SpacetimeDBNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ public class SpacetimeDBNetworkManager : MonoBehaviour
{
internal static SpacetimeDBNetworkManager? _instance;

/// <summary>
/// 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+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
_instance = null;
}

public void Awake()
{
// Ensure that users don't create several SpacetimeDBNetworkManager instances.
Expand Down
24 changes: 23 additions & 1 deletion sdks/csharp/src/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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;
Expand Down Expand Up @@ -242,6 +245,24 @@ private static IReadWrite<Row> Serializer
}
}


#if UNITY_5_3_OR_NEWER
/// <summary>
/// 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+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
_serializer = null;
}
#endif

// The function to use for decoding a type value.
Row DecodeValue(BinaryReader reader) => Serializer.Read(reader);

Expand Down Expand Up @@ -431,7 +452,8 @@ protected virtual void InvokeUpdate(IEventContext context, IStructuralReadWrite
/// </summary>
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))
Expand Down
Loading