diff --git a/workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs b/workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs index 4bcae4bf09..1cb8af77c6 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs +++ b/workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs @@ -103,11 +103,7 @@ public override Subscription Subscribe(EntityId entityId) public override void Cancel(ISubscription subscription) { var sub = ((Subscription) subscription); - if (sub.HasValue) - { - var sender = sub.Value; - sender.IsValid = false; - } + ResetValue(sub); var subscriptions = entityIdToSenderSubscriptions[sub.EntityId]; subscriptions.Remove(sub); @@ -122,7 +118,8 @@ public override void ResetValue(ISubscription subscription) var sub = ((Subscription) subscription); if (sub.HasValue) { - sub.Value.RemoveAllCallbacks(); + var sender = sub.Value; + sender.IsValid = false; } } } @@ -222,12 +219,7 @@ public override Subscription Subscribe(EntityId entityId) public override void Cancel(ISubscription subscription) { var sub = ((Subscription) subscription); - if (sub.HasValue) - { - var receiver = sub.Value; - receiver.IsValid = false; - receiver.RemoveAllCallbacks(); - } + ResetValue(sub); var subscriptions = entityIdToReceiveSubscriptions[sub.EntityId]; subscriptions.Remove(sub); @@ -244,7 +236,9 @@ public override void ResetValue(ISubscription subscription) var sub = ((Subscription) subscription); if (sub.HasValue) { - sub.Value.RemoveAllCallbacks(); + var receiver = sub.Value; + receiver.IsValid = false; + receiver.RemoveAllCallbacks(); } } } diff --git a/workers/unity/Packages/io.improbable.gdk.gameobjectcreation/.codegen/Source/Generators/GameObjectCreation/UnityComponentReaderWriterGenerator.cs b/workers/unity/Packages/io.improbable.gdk.gameobjectcreation/.codegen/Source/Generators/GameObjectCreation/UnityComponentReaderWriterGenerator.cs index 4d2a8069c8..290572b769 100644 --- a/workers/unity/Packages/io.improbable.gdk.gameobjectcreation/.codegen/Source/Generators/GameObjectCreation/UnityComponentReaderWriterGenerator.cs +++ b/workers/unity/Packages/io.improbable.gdk.gameobjectcreation/.codegen/Source/Generators/GameObjectCreation/UnityComponentReaderWriterGenerator.cs @@ -129,12 +129,7 @@ private static TypeBlock GenerateComponentReaderSubscriptionManager(UnityCompone public override void Cancel(ISubscription subscription) {{ var sub = ((Subscription<{componentDetails.Name}Reader>) subscription); - if (sub.HasValue) - {{ - var reader = sub.Value; - reader.IsValid = false; - reader.RemoveAllCallbacks(); - }} + ResetValue(sub); var subscriptions = entityIdToReaderSubscriptions[sub.EntityId]; subscriptions.Remove(sub); @@ -151,7 +146,9 @@ public override void ResetValue(ISubscription subscription) var sub = ((Subscription<{componentDetails.Name}Reader>) subscription); if (sub.HasValue) {{ - sub.Value.RemoveAllCallbacks(); + var reader = sub.Value; + reader.IsValid = false; + reader.RemoveAllCallbacks(); }} }} @@ -262,12 +259,7 @@ private static TypeBlock GenerateComponentWriterSubscriptionManager(UnityCompone public override void Cancel(ISubscription subscription) {{ var sub = ((Subscription<{componentDetails.Name}Writer>) subscription); - if (sub.HasValue) - {{ - var reader = sub.Value; - reader.IsValid = false; - reader.RemoveAllCallbacks(); - }} + ResetValue(sub); var subscriptions = entityIdToWriterSubscriptions[sub.EntityId]; subscriptions.Remove(sub); @@ -284,7 +276,9 @@ public override void ResetValue(ISubscription subscription) var sub = ((Subscription<{componentDetails.Name}Writer>) subscription); if (sub.HasValue) {{ - sub.Value.RemoveAllCallbacks(); + var reader = sub.Value; + reader.IsValid = false; + reader.RemoveAllCallbacks(); }} }} ");