Fix co-op join disconnect: gate client go-in-game on subscene load
A remote/cold client added NetworkStreamInGame the instant it got a
NetworkId, before the gameplay subscene's ghost prefabs finished
streaming. The server's first ghost snapshot then hit a client that
couldn't resolve those prefabs -> "ghost ... ENTITY_NOT_FOUND" ->
forced disconnect ("nothing loads"). On loopback / fast LAN the
go-in-game handshake beats the ~0.4s entity-subscene stream. The host
never hit it (it shares the server's loaded subscene); every remote
join did -- MPPM virtual players and real networked clients alike.
GoInGameClientSystem now gates full-client go-in-game on the gameplay
subscene being loaded (HasSingleton<PlayerSpawner>); thin clients skip
the gate. Verified cross-process in a standalone build over loopback:
join ghost-prefab errors 15->0, disconnects 1->0, client stays
connected and resolves all server ghosts.
Also adds a -mhost / -mjoin <ip> command-line hook to MainMenuController
for headless co-op testing (drives WorldLauncher.StartSession, no UI).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,17 @@ namespace ProjectM.Client
|
|||||||
[BurstCompile]
|
[BurstCompile]
|
||||||
public void OnUpdate(ref SystemState state)
|
public void OnUpdate(ref SystemState state)
|
||||||
{
|
{
|
||||||
|
// A FULL client must not go in-game until the gameplay subscene's ghost prefabs have streamed in.
|
||||||
|
// Otherwise the server's first ghost snapshot arrives before the client can resolve those prefabs
|
||||||
|
// ("ghost ... ENTITY_NOT_FOUND" -> the server disconnects the connection -> "nothing loads"). On
|
||||||
|
// loopback / fast LAN the connect+go-in-game handshake easily beats the ~0.5s entity-subscene stream.
|
||||||
|
// PlayerSpawner is a subscene-baked singleton that co-loads with the ghost prefabs, so its presence
|
||||||
|
// is a sound "subscene ready" gate. Thin clients never instantiate ghosts (and don't stream the
|
||||||
|
// subscene), so they skip the gate and connect immediately.
|
||||||
|
bool isThinClient = (state.WorldUnmanaged.Flags & WorldFlags.GameThinClient) == WorldFlags.GameThinClient;
|
||||||
|
if (!isThinClient && !SystemAPI.HasSingleton<PlayerSpawner>())
|
||||||
|
return;
|
||||||
|
|
||||||
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
||||||
|
|
||||||
foreach (var (_, connection) in
|
foreach (var (_, connection) in
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace ProjectM.Client
|
|||||||
VisualElement _howToPanel;
|
VisualElement _howToPanel;
|
||||||
TextField _ipField;
|
TextField _ipField;
|
||||||
Label _classLabel;
|
Label _classLabel;
|
||||||
|
bool _autoStarted;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -32,10 +33,12 @@ namespace ProjectM.Client
|
|||||||
// The menu owns the cursor.
|
// The menu owns the cursor.
|
||||||
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||||
UnityEngine.Cursor.visible = true;
|
UnityEngine.Cursor.visible = true;
|
||||||
|
_autoStarted = TryAutoStartFromCommandLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
|
if (_autoStarted) return; // headless CLI co-op session; don't build the menu UI
|
||||||
if (_doc == null) _doc = GetComponent<UIDocument>();
|
if (_doc == null) _doc = GetComponent<UIDocument>();
|
||||||
var root = _doc.rootVisualElement;
|
var root = _doc.rootVisualElement;
|
||||||
if (root == null) return;
|
if (root == null) return;
|
||||||
@@ -43,6 +46,28 @@ namespace ProjectM.Client
|
|||||||
BuildMain(root);
|
BuildMain(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dev/automation hook: a player launched with <c>-mhost</c> auto-hosts; <c>-mjoin <ip></c> auto-joins
|
||||||
|
/// (ip optional, defaults to loopback). Lets two standalone builds form a co-op session headlessly for
|
||||||
|
/// testing — the same <see cref="WorldLauncher.StartSession"/> path the menu buttons use, no UI clicks.
|
||||||
|
/// No effect when neither arg is present. Returns true if a session was started.
|
||||||
|
/// </summary>
|
||||||
|
static bool TryAutoStartFromCommandLine()
|
||||||
|
{
|
||||||
|
var args = System.Environment.GetCommandLineArgs();
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
if (args[i] == "-mhost") { WorldLauncher.StartSession(SessionMode.Host, "", false); return true; }
|
||||||
|
if (args[i] == "-mjoin")
|
||||||
|
{
|
||||||
|
string ip = (i + 1 < args.Length && !args[i + 1].StartsWith("-")) ? args[i + 1] : "127.0.0.1";
|
||||||
|
WorldLauncher.StartSession(SessionMode.Join, ip, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void EnsureMenuWorld()
|
static void EnsureMenuWorld()
|
||||||
{
|
{
|
||||||
var w = World.DefaultGameObjectInjectionWorld;
|
var w = World.DefaultGameObjectInjectionWorld;
|
||||||
|
|||||||
Reference in New Issue
Block a user