Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -541,19 +541,28 @@ internal static void ServerResetShudownStateForSceneObjects()
}
}

/// <summary>
/// Gets called only by NetworkSceneManager.SwitchScene
/// </summary>
internal static void ServerDestroySpawnedSceneObjects()
{
foreach (var sobj in SpawnedObjectsList)
//This Allocation is "ok" for now because this code only executes when a new scene is switched to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still real? I don't see an allocation per se...or do you mean the ToList() call?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ToList creates a copy of the collection and allocates a new list object in the process.

//We need to create a new copy the HashSet of NetworkObjects (SpawnedObjectsList) so we can remove
//objects from the HashSet (SpawnedObjectsList) without causing a list has been modified exception to occur.
var spawnedObjects = SpawnedObjectsList.ToList();
foreach (var sobj in spawnedObjects)
{
if ((sobj.IsSceneObject != null && sobj.IsSceneObject == true) || sobj.DestroyWithScene)
{
if (CustomDestroyHandlers.ContainsKey(sobj.PrefabHash))
{
SpawnedObjectsList.Remove(sobj);
CustomDestroyHandlers[sobj.PrefabHash](sobj);
OnDestroyObject(sobj.NetworkObjectId, false);
}
else
{
SpawnedObjectsList.Remove(sobj);
MonoBehaviour.Destroy(sobj.gameObject);
}
}
Expand Down