fix: #3330 #2422 Mirror now ignores objects which inactive parents

This commit is contained in:
vis2k 2023-01-06 14:25:49 +01:00
parent 69d89d8845
commit 5d066f3cd1

View File

@ -1230,7 +1230,15 @@ public static bool SpawnObjects()
if (!active) if (!active)
return false; return false;
NetworkIdentity[] identities = Resources.FindObjectsOfTypeAll<NetworkIdentity>(); // find all NetworkIdentities in the scene.
// all of them are disabled because of NetworkScenePostProcess.
// however, ignore identities under disabled parent objects.
// users would put them under disabled parents to 'deactivate' them.
// those should not be used by Mirror at all.
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3330
IEnumerable<NetworkIdentity> identities = Resources.FindObjectsOfTypeAll<NetworkIdentity>()
.Where(identity => identity.transform.parent == null ||
identity.transform.parent.gameObject.activeInHierarchy);
// first pass: activate all scene objects // first pass: activate all scene objects
foreach (NetworkIdentity identity in identities) foreach (NetworkIdentity identity in identities)