Skip to content

Commit

Permalink
fix: fixing scene object spawning in host mode for 1 scene setup
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jan 31, 2024
1 parent 622d5ce commit 2736fe0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 12 additions & 3 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 0 additions & 2 deletions Assets/Mirage/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2736fe0

Please sign in to comment.