MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.22k stars 770 forks source link

If Server LoadAsync called, client tries to assign networkIds before client has loaded the scene #843

Closed TimsLuxo closed 5 years ago

TimsLuxo commented 5 years ago

Describe the bug Active connection between a Host and a Client, Server uses LoadAsync, which causes OnSpawnSceneObjects call on clients even if client has not loaded scene. Loading same scene on client does not call OnSpawnSceneObjects .

Repro project https://drive.google.com/file/d/1KiMUzHlwhrAx6pFumdBSUW1ZsjLx-uAN/view?usp=sharing

To Reproduce Steps to reproduce the behavior:

  1. Open the attached project in two Editors, or in an Editor and a built exe.
  2. Open scene "TestMirror/TestMainScene" in Editor
  3. Run one instance as Host, the other as Client.
  4. On Host, press "Load Scene On Server" button.
  5. See error on client """Spawn scene object not found for 8F8D96E8FD34F75 SpawnableObjects.Count=0 UnityEngine.Debug:LogError(Object) Mirror.ClientScene:OnSpawnSceneObject(NetworkConnection, SpawnSceneObjectMessage) (at Assets/Mirror/Runtime/ClientScene.cs:446)"""
  6. See that subscene NetCube is disabled and has a netid of 0 on client.

This happens whether or not client scene loaded after scene is loaded on server (see TestNetworkManager.LoadScene)

Expected behavior NetCube is Active and had valid netId.

  1. When server loads the scene it SHOULD NOT call ClientScene:OnSpawnSceneObject on client, nor should it disable the NetCube.
  2. When client loads the scene it SHOULD call ClientScene:OnSpawnSceneObject on itself.

Screenshots None

Desktop (please complete the following information):

Additional context Our main use case is between two editors on two machines, but this happens with built exes on same or different machines.

MrGadget1024 commented 5 years ago

If you call NetworkManager.ServerChangeScene(string newSceneName) the server will tell the clients to change scenes and will suspend msgs until they're ready.