From 9bdaa10e1a7229e3482f89055b3b60016f1b8048 Mon Sep 17 00:00:00 2001 From: MirCore <9919366+MirCore@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:46:03 +0100 Subject: [PATCH 1/3] Re-initialize FFIClient on entering Play mode without a domain reload The Editor raises Application.quitting when Play mode exits, so Quit() disposes the client and sets _isDisposed. Without a domain reload the flag stays set in the next Play session, every FFI event is dropped and Room.Connect times out waiting for ReadyForRoomEventRequest. Co-Authored-By: Claude Opus 5.5 --- Runtime/Scripts/Internal/FFI/FFIClient.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Runtime/Scripts/Internal/FFI/FFIClient.cs b/Runtime/Scripts/Internal/FFI/FFIClient.cs index 213ee1f4..18bdfa31 100644 --- a/Runtime/Scripts/Internal/FFI/FFIClient.cs +++ b/Runtime/Scripts/Internal/FFI/FFIClient.cs @@ -107,6 +107,23 @@ static void OnAfterAssemblyReload() { InitializeSdk(); } + + // The Editor raises Application.quitting when Play mode stops, so Quit() disposes the + // client at the end of every Play session. With a domain reload the next session starts + // from fresh statics; with Enter Play Mode Options skipping the reload, _isDisposed stays + // true and every event from Rust is dropped, so connects time out waiting for + // ReadyForRoomEventRequest. Bring the client back up for the new session instead. + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + static void ReinitializeOnEnterPlayMode() + { + if (!_isDisposed) + return; + + _isDisposed = false; + AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload; + AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload; + InitializeSdk(); + } #else [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void Init() From 2578cf512963610ca088307f0fd764e8cca5780a Mon Sep 17 00:00:00 2001 From: MirCore <9919366+MirCore@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:19:52 +0100 Subject: [PATCH 2/3] Clear FfiClient event subscribers on Dispose Rooms and streams from an earlier Play session stayed subscribed to the singleton and were kept alive once it was re-initialized without a domain reload. --- Runtime/Scripts/Internal/FFI/FFIClient.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Runtime/Scripts/Internal/FFI/FFIClient.cs b/Runtime/Scripts/Internal/FFI/FFIClient.cs index 18bdfa31..551a8277 100644 --- a/Runtime/Scripts/Internal/FFI/FFIClient.cs +++ b/Runtime/Scripts/Internal/FFI/FFIClient.cs @@ -276,9 +276,27 @@ public void Dispose() } ); ClearPendingCallbacks(); + ClearEventSubscribers(); Utils.Debug("FFIServer - Disposed"); } + // Every subscriber holds native handles that the DisposeRequest just invalidated. Drop them so + // rooms and streams left over from an earlier Play session are not kept alive by this + // singleton once it is re-initialized without a domain reload. + private void ClearEventSubscribers() + { + DisconnectReceived = null; + PanicReceived = null; + RoomEventReceived = null; + TrackEventReceived = null; + RpcMethodInvocationReceived = null; + VideoStreamEventReceived = null; + AudioStreamEventReceived = null; + ByteStreamReaderEventReceived = null; + TextStreamReaderEventReceived = null; + DataTrackStreamEventReceived = null; + } + internal void RegisterPendingCallback( ulong requestAsyncId, Func selector, From a4468bfa019cc566f32f60a01245a51d548c3df7 Mon Sep 17 00:00:00 2001 From: Max Heimbrock <43608204+MaxHeimbrock@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:47:13 +0100 Subject: [PATCH 3/3] test --- Runtime/Scripts/Internal/FFI/FFIClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Runtime/Scripts/Internal/FFI/FFIClient.cs b/Runtime/Scripts/Internal/FFI/FFIClient.cs index 551a8277..4b1d1b76 100644 --- a/Runtime/Scripts/Internal/FFI/FFIClient.cs +++ b/Runtime/Scripts/Internal/FFI/FFIClient.cs @@ -98,6 +98,7 @@ static FfiClient() Application.quitting += Quit; } + static void OnBeforeAssemblyReload() { Instance.Dispose();