Skip to content

Re-initialize FFIClient on entering Play mode without a domain reload - #396

Merged
MaxHeimbrock merged 2 commits into
livekit:mainfrom
MirCore:fix/editor-play-mode-without-domain-reload
Nov 16, 2026
Merged

MaxHeimbrock merged 2 commits into
livekit:mainfrom
MirCore:fix/editor-play-mode-without-domain-reload

Conversation

@MirCore

@MirCore MirCore commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Background

When Enter Play Mode Options skip the domain reload, FFIClient stays disposed after the first Play session. The Editor raises Application.quitting on Play mode exit, and Quit() → Dispose() sets _isDisposed, which only a new domain resets. Every later session drops all FFI events, so Room.Connect times out waiting for ReadyForRoomEventRequest.

Fixes #395.

Changes

  • Adds an Editor-only [RuntimeInitializeOnLoadMethod(SubsystemRegistration)] hook to FFIClient. If the previous Play session disposed the client, it clears _isDisposed, re-subscribes the before/after assembly-reload handlers that Quit() removed, and calls InitializeSdk().
  • The hook does nothing after a domain reload (the flag is already false) and is compiled out of Player builds by the existing #if UNITY_EDITOR.
  • Dispose() now clears all FfiClient event subscribers after ClearPendingCallbacks() (2578cf5). All current subscribers are per-instance (Room, the audio/video/byte/text streams, DataTrack) and their native handles are invalid after the DisposeRequest, so nothing needs to survive. Without this, rooms and streams from earlier Play sessions stayed reachable through the singleton when domain reload is off.

Testing

  • Unity 6000.7.0b8, Windows: connected to a room in 3 consecutive Play sessions with domain reload off, and in 2 with it on.
  • With domain reload off, each of the 3 sessions had exactly one subscriber on RoomEventReceived, DisconnectReceived and AudioStreamEventReceived, and all were back to 0 after Play mode stopped.
  • Not run: the SDK test suite (Scripts~/run_unity.sh with a local livekit-server). Not tested on Unity 2022.3 / 6000.0 or non-Windows Editors.

Generated with Claude Code

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 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Nov 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

devin-ai-integration[bot]

This comment was marked as resolved.

MirCore added a commit to TrIVAs-XR/TrIVA-Unity that referenced this pull request Nov 10, 2026
Uses MirCore/client-sdk-unity at 9bdaa10 until livekit/client-sdk-unity#396 is merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxHeimbrock

Copy link
Copy Markdown
Contributor

I see our CI is not fit to check on forks, I will also look into this.

@MaxHeimbrock

Copy link
Copy Markdown
Contributor

I am able to repro this on MacOS and Unity 6000.3.10f1 and can see your PR fixes the issue. I will wait for you to also include the fix to the events and then see how we satisfy the CI. Thanks for the contribution.

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.

@MaxHeimbrock MaxHeimbrock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the CI on my own copy and it looks good. Merge when you feel like it.

@MaxHeimbrock

Copy link
Copy Markdown
Contributor

CI run: #398

@MaxHeimbrock
MaxHeimbrock merged commit 96742a6 into livekit:main Nov 16, 2026
9 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Room connect times out in the Editor after the first Play session when domain reload is disabled

3 participants