MirrorNetworking / Mirror

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

Scene Interest Management component KeyNotFoundException #3039

Closed wesleywh closed 2 years ago

wesleywh commented 2 years ago

Describe the bug

Additive Scenes using Scene Interest Management component throws the follow error in hosted mode:

KeyNotFoundException: The given key was not present in the dictionary

That line shows: Scene currentScene = lastObjectScene[identity];

The lastObjectScene is normally populated (I think) in the OnSpawned function. Logging that function it is never called. Is there a setup issue I have done that I need to be aware of or is this a bug in this code? Using unity 2020.3.14f1 (LTS), with using Mirror: 55.2.1

How To Reproduce

  1. Open Unity 2020.3
  2. Import Mirror v55.3.5
  3. Add "Assets/Mirror/Examples/AdditiveScenes/Scenes/MainScene.unity" To Build Settings Index 0
  4. Add "Assets/Mirror/Examples/AdditiveScenes/Scenes/SubScene.unity" to build settings index 1
  5. Open MainScene and modify NetworkManager to include Scene Interest Managment component a. Select the NetworkManager gameobject b. Delete the Distance Interest Management component c. Add the Scene Interest Management component
  6. Click play in the unity editor
  7. Select the Host (Server + Client) button
  8. Open the console - view the ever increasing number of errors

Expected behavior

When spawning a network identity it should trigger the OnSpawned event in the Scene Interest Management component. It doesn't seem to do that, which triggers an endless error being thrown (which will cause a game to eventually crash). It should be populating the lastObjectScene dictionary.

Desktop (please complete the following information):

Additional context I have deleted all my project files, reimported them, restarted my computer, nothing.

MrGadget1024 commented 2 years ago

Fixed by https://github.com/vis2k/Mirror/commit/893cb4590ab9d23b81b733f91503f6077bd793b9