This commit is contained in:
vis2k 2021-03-07 18:08:37 +08:00
parent 5a9d7921c5
commit 9abc60c62b

View File

@ -778,8 +778,8 @@ internal static void OnObjectSpawnFinished(ObjectSpawnFinishedMessage _)
//Debug.Log("SpawnFinished"); //Debug.Log("SpawnFinished");
ClearNullFromSpawned(); ClearNullFromSpawned();
// paul: Initialize the objects in the same order as they were initialized // paul: Initialize the objects in the same order as they were
// in the server. This is important if spawned objects // initialized in the server. This is important if spawned objects
// use data from scene objects // use data from scene objects
foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values.OrderBy(uv => uv.netId)) foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values.OrderBy(uv => uv.netId))
{ {
@ -793,8 +793,9 @@ internal static void OnObjectSpawnFinished(ObjectSpawnFinishedMessage _)
static readonly List<uint> toRemoveFromSpawned = new List<uint>(); static readonly List<uint> toRemoveFromSpawned = new List<uint>();
static void ClearNullFromSpawned() static void ClearNullFromSpawned()
{ {
// spawned has null objects after changing scenes on client using NetworkManager.ServerChangeScene // spawned has null objects after changing scenes on client using
// remove them here so that 2nd loop below does not get NullReferenceException // NetworkManager.ServerChangeScene remove them here so that 2nd
// loop below does not get NullReferenceException
// see https://github.com/vis2k/Mirror/pull/2240 // see https://github.com/vis2k/Mirror/pull/2240
// TODO fix scene logic so that client scene doesn't have null objects // TODO fix scene logic so that client scene doesn't have null objects
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned) foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)