fix: PrepareToSpawnSceneObjects checks netId instead of activeSelf [fixes: #3541] (#3543)

* fix: fixing PrepareToSpawnSceneObjects not added enabled objects

fixes: https://github.com/MirrorNetworking/Mirror/issues/3541

Should be safe to remove this extra check complete, it is safe to add spawned object to `spawnableObjects`. For now this just changes it to NetId to ensure that the object really is unspawned and not just enabled

* Update NetworkClient.cs

---------

Co-authored-by: mischa <16416509+vis2k@users.noreply.github.com>
This commit is contained in:
James Frowen 2023-07-06 08:56:23 +01:00 committed by GitHub
parent 110625b102
commit 51c7162af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1193,11 +1193,12 @@ public static void PrepareToSpawnSceneObjects()
foreach (NetworkIdentity identity in allIdentities) foreach (NetworkIdentity identity in allIdentities)
{ {
// add all unspawned NetworkIdentities to spawnable objects // add all unspawned NetworkIdentities to spawnable objects
// need to ensure it's not active yet because // need to check netId to make sure object is not spawned
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3541
// PrepareToSpawnSceneObjects may be called multiple times in case // PrepareToSpawnSceneObjects may be called multiple times in case
// the ObjectSpawnStarted message is received multiple times. // the ObjectSpawnStarted message is received multiple times.
if (Utils.IsSceneObject(identity) && if (Utils.IsSceneObject(identity) &&
!identity.gameObject.activeSelf) identity.netId == 0)
{ {
if (spawnableObjects.TryGetValue(identity.sceneId, out NetworkIdentity existingIdentity)) if (spawnableObjects.TryGetValue(identity.sceneId, out NetworkIdentity existingIdentity))
{ {