diff --git a/Components/SeamlessSwitcher.cs b/Components/SeamlessSwitcher.cs index 30b86ea..f0c494c 100644 --- a/Components/SeamlessSwitcher.cs +++ b/Components/SeamlessSwitcher.cs @@ -264,7 +264,12 @@ namespace SeamlessClient.Components } + //Following event doesnt clear networked replicables MyMultiplayer.Static.ReplicationLayer.Dispose(); + ClearClientReplicables(); + + + PreventRPC = true; StartPacketCheck = true; @@ -273,6 +278,24 @@ namespace SeamlessClient.Components } + private void ClearClientReplicables() + { + MyReplicationClient replicationClient = (MyReplicationClient)MyMultiplayer.Static.ReplicationLayer; + + Dictionary networkedobjs = (Dictionary)typeof(MyReplicationLayer).GetField("m_networkIDToObject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(replicationClient); + + MethodInfo destroyreplicable = typeof(MyReplicationClient).GetMethod("ReplicableDestroy", BindingFlags.Instance | BindingFlags.NonPublic); + + int i = 0; + foreach(var obj in networkedobjs) + { + destroyreplicable.Invoke(replicationClient, new object[] { obj.Value, true }); + i++; + } + + Seamless.TryShow($"Cleared {i} replicables"); + } + private void OnUserJoined(JoinResult joinResult) { isSwitchingServer = false;