Skip to content

Commit

Permalink
fix: cleaning up behaviours after stopping server/client
Browse files Browse the repository at this point in the history
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
  • Loading branch information
James-Frowen committed Apr 11, 2022
1 parent 0338d85 commit ab623a3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions source/SyncPositionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -192,6 +196,25 @@ private void ServerStarted()
Server.MessageHandler.RegisterHandler<NetworkPositionSingleMessage>(ServerHandleNetworkPositionMessage);
}

private void ClientStopped(ClientStoppedReason arg0)
{
Cleanup();
}

private void ServerStopped()
{
Cleanup();
}

/// <summary>
/// shared clean up for both server/client
/// </summary>
private void Cleanup()
{
// clear all just incase they fail to remove themselves
Behaviours.ClearBehaviours();
}


#region Sync Server -> Client
private void LateUpdate()
Expand Down

0 comments on commit ab623a3

Please sign in to comment.