Hi!
We have a menuScene where the users can connect to a multiplayer room. After connecting to the server the players starts the game by loading the game world scene. (using SceneManager.LoadSceneAsync)
We have our own gameobject MultiplayerManager with DontDestroyOnLoad set that has a reference to the bridge in the starting menuScene, this game object contains following code for Awake and OnSceneLoaded:
void Awake()
-
{*
-
if (instance == null)*
-
{*
-
DontDestroyOnLoad(this.gameObject);*
-
instance = this;*
-
}*
-
else*
-
{*
-
Destroy(gameObject);*
-
}*
-
// Move the bridge to DontDestroyOnLoad but still*
-
// instantiate into the active scene*
-
var scene = bridge.gameObject.scene;*
-
DontDestroyOnLoad(bridge);*
-
bridge.InstantiationScene = scene;*
-
// Make the query find the bridge*
-
query.BridgeResolve += _ => bridge;*
-
// Make new CoherenceSync:s find the bridge*
-
CoherenceSync.BridgeResolve += _ => bridge;*
-
// Get notified if the scene is changed*
-
SceneManager.sceneLoaded += OnSceneLoaded;*
-
*
-
}*
-
void OnSceneLoaded(Scene scene, LoadSceneMode mode)*
-
{*
-
*
-
// Moves the client connection to another scene on the server*
-
bridge.SceneManager.SetClientScene(scene.buildIndex);*
-
// Instantiate remote entities into the new scene instead*
-
bridge.InstantiationScene = scene;*
-
}*
Loading the game world scene seems to be working fine, but then when we try to go back to the menu Scene again we get the following null pointer exception after loading in the menu scene:
NullReferenceException: Object reference not set to an instance of an object
Coherence.Toolkit.CoherenceQuery.Start () (at Library/PackageCache/io.coherence.sdk@1.1.3/Coherence.Toolkit/CoherenceQuery.cs:41)
line 41 there looks like this
bridge.OnAfterFloatingOriginShifted += OnFloatingOriginShiftedInternal;
We also get a nullpointer exception from our MultiplayerManager object when it tries to use the reference to the main query on this line in the OnSceneLoaded function:
bridge.SceneManager.SetClientScene(scene.buildIndex);
Best Regards
Simon