Skip to content

Commit

Permalink
fix: fixing scene events not firing when host connects
Browse files Browse the repository at this point in the history
client start/finish events still need to be invoked for host player so that scripts like characterspawner work correctly
  • Loading branch information
James-Frowen committed Nov 27, 2022
1 parent cf6ef20 commit 598057e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Assets/Mirage/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,32 @@ protected internal virtual void OnServerAuthenticated(INetworkPlayer player)

// dont need to load scenes for host player (they already have them loadeed becuase they are the serve)
if (Server.LocalPlayer == player)
{
HostPlayerAuthenticated();
return;
}

var additiveScenes = GetAdditiveScenes();

player.Send(new SceneMessage { MainActivateScene = ActiveScenePath, AdditiveScenes = additiveScenes });
player.Send(new SceneReadyMessage());
}

/// <summary>
/// for host, server loads scene not client, so we need special handling for host client so that other components like CharacterSpawner work correctly
/// </summary>
void HostPlayerAuthenticated()
{
// nornal client invokes start, then finish, even if scene is already loaded
OnClientStartedSceneChange?.Invoke(ActiveScenePath, SceneOperation.Normal);

// server server and client copy of hoost player as ready
Server.LocalClient.Player.SceneIsReady = true;
Server.LocalPlayer.SceneIsReady = true;

OnClientFinishedSceneChange?.Invoke(SceneManager.GetActiveScene(), SceneOperation.Normal);
}

private static List<string> GetAdditiveScenes()
{
var additiveScenes = new List<string>(SceneManager.sceneCount - 1);
Expand Down

0 comments on commit 598057e

Please sign in to comment.