Skip to content

Commit

Permalink
feat: NetworkSceneChecker use Scene instead of string name (#1496)
Browse files Browse the repository at this point in the history
* NetworkSceneChecker use Scene instead of string name

* Added comment
  • Loading branch information
MrGadget committed Feb 15, 2020
1 parent 4c4a52b commit 7bb80e3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Assets/Mirror/Components/NetworkSceneChecker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

namespace Mirror
{
Expand All @@ -20,14 +21,15 @@ public class NetworkSceneChecker : NetworkBehaviour
[Tooltip("Enable to force this object to be hidden from all observers.")]
public bool forceHidden;

public static readonly Dictionary<string, HashSet<NetworkIdentity>> sceneCheckerObjects = new Dictionary<string, HashSet<NetworkIdentity>>();
// Use Scene instead of string scene.name because when additively loading multiples of a subscene the name won't be unique
static readonly Dictionary<Scene, HashSet<NetworkIdentity>> sceneCheckerObjects = new Dictionary<Scene, HashSet<NetworkIdentity>>();

string currentScene;
Scene currentScene;

[ServerCallback]
void OnEnable()
{
currentScene = gameObject.scene.name;
currentScene = gameObject.scene;
if (LogFilter.Debug) Debug.Log($"NetworkSceneChecker.OnEnable currentScene: {currentScene}");
}

Expand All @@ -42,7 +44,7 @@ public override void OnStartServer()
[ServerCallback]
void Update()
{
if (currentScene == gameObject.scene.name)
if (currentScene == gameObject.scene)
return;

// This object is in a new scene so observers in the prior scene
Expand All @@ -55,7 +57,7 @@ void Update()
RebuildSceneObservers();

// Set this to the new scene this object just entered
currentScene = gameObject.scene.name;
currentScene = gameObject.scene;

// Make sure this new scene is in the dictionary
if (!sceneCheckerObjects.ContainsKey(currentScene))
Expand Down

0 comments on commit 7bb80e3

Please sign in to comment.