Skip to content

Can't write to SyncVar when reusing pooled object. #911

@TheoLemoine

Description

@TheoLemoine

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions