MirrorNetworking / Mirror

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

Load Additive and Proximity Checkers Not Working Together. #573

Closed MrGadget1024 closed 5 years ago

MrGadget1024 commented 5 years ago

Unity 2018.3.8 / Mirror 2184 Repro Project Attached

There's a trigger zone in the middle of the Main Scene that's Server Only with a Zone Handler script that fires a TargetRpc to player that enters the zone to load the sub scene. There's a ZoneVisualizer with a semi-transparent material so you can see where it should trigger.

There are 4 networked objects with proximity checkers in the corners of the Main scene...they have semi-transparent spheres showing their ranges. These work correctly if you move the player toward them.

1st Bug There are the same 4 networked objects with proximity checkers in the middle of the SubScene. These should be hidden when the SubScene loads until player gets close to them...instead they all are shown immediately when the SubScene is loaded.

2nd Bug If you run LAN server in editor and LAN client as built, the SubScene content never appears in the client, despite log messages that say it's loaded, even when player gets to the scene center where it'd be right among the cluster of prefabs there.

MirrorAdditiveTest.zip

image

miwarnec commented 5 years ago

@MrGadget1024 can you try with latest master again? fixed another sceneid issue today.

MrGadget1024 commented 5 years ago

No change in behavior with latest master this morning. Updated linked repo project linked above.

MrGadget1024 commented 5 years ago

A while back when Paul fixed Additive the last time, I had to call NetworkServer.SpawnObjects() after loading additive scenes on the server, and I had to call ClientScene.PrepareToSpawnSceneObjects() on the client after it loaded an additive scene.

NetworkServer.SpawnObjects() throws a flood of errors so I commented that out in the server. The additive scene on the server appears to load up fine.

ClientScene.PrepareToSpawnSceneObjects() doesn't seem to make any difference on the client. The scene is loaded additive when it should, but everything is immediately visible even though I'm out of range of the proximity checkers of the sub-scene objects.

MrGadget1024 commented 5 years ago

Updated repro to latest Mirror

miwarnec commented 5 years ago

taking a look at this now. last open bug, here we go..

miwarnec commented 5 years ago

going to share my findings here along the way. image you can call LoadSceneAsync in OnStartServer directly, no couroutine / yield magic needed

miwarnec commented 5 years ago

image same for UnloadScenes

miwarnec commented 5 years ago

image OfflineScene & OfflineGUI seems to be unnecessary. please avoid that in next bug report :)

miwarnec commented 5 years ago

SceneLoader.cs simplified: image

please try to keep it as simple as possible next time. this takes a lot of time to dig through and understand

miwarnec commented 5 years ago

looks like LoadSceneAsync doesn't trigger NetworkScenePostProcess, which is why the additively loaded scene objects don't contains the scene hash. that's a problem.

miwarnec commented 5 years ago

that is also the reason why they aren't being disabled on load

miwarnec commented 5 years ago

image onpostprocesscene is actually called. but SceneManager.GetActiveScene().name is MainScene each time because the additively loaded scene isn't the main scene. hmm

miwarnec commented 5 years ago

host mode of the example seems to load subscene twice when walking into it, because server already loaded it in onstartserver once. will avoid host mode

miwarnec commented 5 years ago

got it working in my tests @MrGadget1024 . we will need two fixes:

  1. OnPostProcessScene needs to include all scenes, not just getactivescene (but still exclude dontdestroyonload)
  2. NetworkManager needs SceneManager.sceneLoaded += OnSceneLoa image ded:

this definitely works. I will add this to master after some more tests. afterwards we'll have to figure out a more consistent way for PrepareToSpawnSceneObjects and SpawnObjects. ideally one way that works in all cases.

miwarnec commented 5 years ago

fixed in master. thanks for repro project mrgadget.

miwarnec commented 5 years ago

:tada: This issue has been resolved in version 1.4.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

MrGadget1024 commented 5 years ago

Please retest with repro attached to this comment

MirrorLoadAdditive.zip

image

miwarnec commented 5 years ago

:tada: This issue has been resolved in version 1.4.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: