I'm implementing scene loading in my networked Unity game using FishNet, but experiencing a critical issues. The player falls through the floor while the scene is loading. I've tried many workarounds, and I'm getting somewhat close with disabling/re-enabling the character controllers, but the issue is the observer rpc for enabling the players doesn't run on clients.
Example: A client causes the scene change, both client and server freeze for a bit, the server lands and loads as expected but the client isn't re-enabled
[ServerRpc(RequireOwnership = false)]
private void LoadScene(string sceneName)
{
// Find and disable all players
Player[] players = GameObject.FindObjectsOfType<Player>();
DisableAllPlayers();
SceneLoadData sld = new SceneLoadData()
{
SceneLookupDatas = new[] { new SceneLookupData(sceneName) },
MovedNetworkObjects = new NetworkObject[players.Length],
ReplaceScenes = ReplaceOption.All,
Options = new LoadOptions()
{
AutomaticallyUnload = true,
AllowStacking = false,
}
};
// Move all players to the new scene
for (int i = 0; i < players.Length; i++)
{
sld.MovedNetworkObjects[i] = players[i].GetComponent<NetworkObject>();
}
InstanceFinder.SceneManager.OnLoadEnd += OnSceneLoadComplete;
SceneManager.LoadGlobalScenes(sld);
}
private void OnSceneLoadComplete(SceneLoadEndEventArgs args)
{
InstanceFinder.SceneManager.OnLoadEnd -= OnSceneLoadComplete;
EnableAllPlayers(); // This works on server but not clients
}