adjust how syncable cache works

This commit is contained in:
2025-03-24 17:34:48 +02:00
parent 8edfcff56f
commit f5ad619ed5
2 changed files with 6 additions and 6 deletions

View File

@@ -61,9 +61,9 @@ namespace BoneSync.Sync.Components
{ {
public const int OBJECT_SYNC_FPS = 20; public const int OBJECT_SYNC_FPS = 20;
public static Dictionary<GameObject, Syncable> syncablesCache = new Dictionary<GameObject, Syncable>(); public static Dictionary<int, Syncable> syncablesCache = new Dictionary<int, Syncable>();
public Syncable(IntPtr intPtr) : base(intPtr) { public Syncable(IntPtr intPtr) : base(intPtr) {
syncablesCache[gameObject] = this; syncablesCache[gameObject.GetHashCode()] = this;
} }
private bool _syncCoroutineRunning; private bool _syncCoroutineRunning;
@@ -166,7 +166,7 @@ namespace BoneSync.Sync.Components
public void OnEnable() public void OnEnable()
{ {
syncablesCache[gameObject] = this; syncablesCache[gameObject.GetHashCode()] = this;
FindAndUpdateComponents(); FindAndUpdateComponents();
@@ -321,7 +321,7 @@ namespace BoneSync.Sync.Components
} }
if (gameObject) syncablesCache.Remove(gameObject); if (gameObject) syncablesCache.Remove(gameObject.GetHashCode());
ObjectSyncCache.RemoveSyncable(this); ObjectSyncCache.RemoveSyncable(this);

View File

@@ -154,7 +154,7 @@ namespace BoneSync.Sync
private static Syncable _GetSyncableFromCache(GameObject gameObject) private static Syncable _GetSyncableFromCache(GameObject gameObject)
{ {
bool success = Syncable.syncablesCache.TryGetValue(gameObject, out Syncable syncable); bool success = Syncable.syncablesCache.TryGetValue(gameObject.GetHashCode(), out Syncable syncable);
if (!success) if (!success)
{ {
return null; return null;
@@ -173,7 +173,7 @@ namespace BoneSync.Sync
} }
public static Syncable MakeOrGetSyncable(GameObject gameObject) public static Syncable MakeOrGetSyncable(GameObject gameObject)
{ {
Syncable syncable = _GetSyncableFromCache(gameObject); // buttons must never be a sub syncable Syncable syncable = _GetSyncableFromCache(gameObject);
if (syncable == null) if (syncable == null)
{ {
syncable = _MakeOrGetSyncable(gameObject); syncable = _MakeOrGetSyncable(gameObject);