From ab623a3e617848807a1483b2e1783e0adf8e2623 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Mon, 11 Apr 2022 20:00:57 +0100 Subject: [PATCH] fix: cleaning up behaviours after stopping server/client Stop not being called should be fixed in mirage, but clearing behaviours list will avoid future issues if stops isn't called for some reason --- source/SyncPositionSystem.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/SyncPositionSystem.cs b/source/SyncPositionSystem.cs index 9f91467..5b8e2d2 100644 --- a/source/SyncPositionSystem.cs +++ b/source/SyncPositionSystem.cs @@ -161,10 +161,14 @@ internal void Awake() Server?.Started.AddListener(ServerStarted); Client?.Started.AddListener(ClientStarted); + Server?.Stopped.AddListener(ServerStopped); + Client?.Disconnected.AddListener(ClientStopped); + _timeSync = new InterpolationTime(1 / SyncRate, tickDelay: TickDelayCount, timeScale: 0.1f); packer = new SyncPacker(PackSettings); } + private void OnValidate() { packer = new SyncPacker(PackSettings ?? new SyncSettings()); @@ -192,6 +196,25 @@ private void ServerStarted() Server.MessageHandler.RegisterHandler(ServerHandleNetworkPositionMessage); } + private void ClientStopped(ClientStoppedReason arg0) + { + Cleanup(); + } + + private void ServerStopped() + { + Cleanup(); + } + + /// + /// shared clean up for both server/client + /// + private void Cleanup() + { + // clear all just incase they fail to remove themselves + Behaviours.ClearBehaviours(); + } + #region Sync Server -> Client private void LateUpdate()