-
-
Notifications
You must be signed in to change notification settings - Fork 183
Description
Fishnet version 4.6.8Pro
Hi, we encountered an issue with pooled objects and SyncVar while updating fishnet to v4.6.8. When reusing an object from the pool, any write to a SyncVar before Spawn is ignored.
We have this pseudo code that crashes when reusing an instance from the pool :
// Get object from pool
NetworkObject weapon = NetworkManager.GetPooledInstantiated(weaponPrefab.NetworkObject, true);
// Setup some sync var
weapon.WeaponOwner.Value = this; // This is NOT Null
// Do some setup ... ----> CRASH (Because weapon.WeaponOwner.Value is null)
weapon.WeaponOwner.Value.SetWeapon(weapon);
// Spawn pooled object
InstanceFinder.ServerManager.Spawn(weapon, Owner);
This happens because the SyncVar reject the Value = because of SyncVar's SetValue() code
//Object is deinitializing.
if (isNetworkInitialized && CodegenHelper.NetworkObject_Deinitializing(this.NetworkBehaviour))
return; // We return here because NB.IsDeinitializing == true
From what I saw, IsDeinitializing
is only reset in NetworkObject.Spawn()
.This is an issue for pooled objects, which are reused and try to setup values before spawn.
Looks like an issue with how fishnet handles pooled objects. Do you have an idea on how to fix it ?
To summarize the repro step are:
Retrieve object from pool,,
Write to some syncvar (✅ Sync var is written correctly),,
Spawn it,,
Despawn it (which returns the object to the pool),,
Retrieve the same object from pool,,
Write to some SyncVar -> ❌ SyncVar write is ignored because NetworkBehaviour.IsDeInitializing
was not reset (because we didn't call spawn yet)