From 2736fe0def7d22c18e878bcdd4cc845bd8f3e746 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Wed, 31 Jan 2024 18:37:52 +0000 Subject: [PATCH] fix: fixing scene object spawning in host mode for 1 scene setup --- Assets/Mirage/Runtime/NetworkServer.cs | 15 ++++++++++++--- Assets/Mirage/Runtime/ServerObjectManager.cs | 2 -- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Assets/Mirage/Runtime/NetworkServer.cs b/Assets/Mirage/Runtime/NetworkServer.cs index cbc45eb1b9..2733ce2924 100644 --- a/Assets/Mirage/Runtime/NetworkServer.cs +++ b/Assets/Mirage/Runtime/NetworkServer.cs @@ -287,16 +287,25 @@ public void StartServer(NetworkClient localClient = null) // make sure to call ServerObjectManager start before started event // this is too stop any race conditions where other scripts add their started event before SOM is setup if (ObjectManager != null) + { ObjectManager.ServerStarted(this); + // if no hostClient, then spawn objects right away + if (LocalClient == null) + ObjectManager.SpawnOrActivate(); + } _started?.Invoke(); if (LocalClient != null) { - // we should call onStartHost after transport is ready to be used - // this allows server methods like ServerObjectManager.Spawn to be called in there + localClient.ConnectHost(this, dataHandler); + + // onStartHost needs to be called after the client is active _onStartHost?.Invoke(); - localClient.ConnectHost(this, dataHandler); + // spawn scene objects in starting scene AFTER host client has activated, + // otherwise IsClient will be false for objects in starting scene + ObjectManager.SpawnOrActivate(); + Connected?.Invoke(LocalPlayer); if (logger.LogEnabled()) logger.Log("NetworkServer StartHost"); diff --git a/Assets/Mirage/Runtime/ServerObjectManager.cs b/Assets/Mirage/Runtime/ServerObjectManager.cs index 47f58c9120..4f70e47e84 100644 --- a/Assets/Mirage/Runtime/ServerObjectManager.cs +++ b/Assets/Mirage/Runtime/ServerObjectManager.cs @@ -55,8 +55,6 @@ internal void ServerStarted(NetworkServer server) DefaultVisibility = new AlwaysVisible(this); _rpcHandler = new RpcHandler(_server.MessageHandler, _server.World, RpcInvokeType.ServerRpc); - - SpawnOrActivate(); } private void OnServerStopped()