Table of Contents

Class PersistentPool

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Returns network objects to FishNet's pool somewhere a scene unload cannot destroy them.

public static class PersistentPool
Inheritance
PersistentPool
Inherited Members

Remarks

FishNet leaves a despawned object wherever it was, and a spawn moves a pooled one into its target scene, so an instance that had ever been used sat in the pool inside its world scene and died with that scene when it unloaded — while the pool, and the spawner's reservation, still counted it. The spawner's own despawns were moved out of the world scenes first (hot-path audit finding L15); a corpse with no spawner, ground loot and a container placed by script still went back to the pool in place, and every one of them was lost at the unload.

Every path that returns a once-spawned object to FishNet's pool goes through Despawn(NetworkManager, NetworkObject), and every path that puts one back some other way (a spawn rolled back before it happened, a prewarm) calls Keep(NetworkManager, NetworkObject), so they share one rule for where a pooled object lives: out of every world scene, in DontDestroyOnLoad, inactive until a spawn moves it into its scene again. The callers:

  • Despawn(NetworkManager, NetworkObject): the spawner (SpawnerRuntime.Despawn); the spawner-less fallbacks NPC.ReturnToPool and Interactable.Despawn; pets (Pet.Despawn, PetSystem.DespawnPet); a boss's adds (BossScriptState.DismissAdds); and characters (CharacterSystem.SaveAndDespawnCharacter, CharacterSystem.EvictLostCharacter, and CharacterSystem.DespawnLingeringBody for a combat-logout body).
  • Keep(NetworkManager, NetworkObject): the spawner's prewarm (SpawnerPool.Reserve) and its rolled-back spawn (SpawnerRuntime.RollBackUnfinishedSpawn); a boss add rolled back (BossScriptState.RollBackAdd); a pooled pet object with no Pet (PetSystem.SpawnAndInitializePet); and the two character paths above (EvictLostCharacter, DespawnLingeringBody) when the object was no longer spawned.

Methods

Despawn(NetworkManager, NetworkObject)

Despawns a spawned object into FishNet's pool and keeps it out of the world scenes. Server only.

public static bool Despawn(NetworkManager networkManager, NetworkObject instance)

Parameters

networkManager NetworkManager

The network manager owning the pool.

instance NetworkObject

The spawned object.

Returns

bool

True when the object was spawned and has been despawned.

Keep(NetworkManager, NetworkObject)

Keeps a pooled instance out of the world scenes, so no scene's unload can destroy it.

public static void Keep(NetworkManager networkManager, NetworkObject instance)

Parameters

networkManager NetworkManager

The network manager owning the pool.

instance NetworkObject

The pooled instance.

Remarks

Call for an instance that has just gone back into FishNet's pool. It is inactive there, and a spawn moves it into its target scene again, exactly as it does an instance a prewarm made.

Only for FishNet's own pool, which does not place what it stores; a custom pool keeps its objects where it chooses. Only in play mode, and only for a root object, which is all UnityEngine.Object.DontDestroyOnLoad(UnityEngine.Object) accepts. Never for a scene object: FishNet does not pool one at all — it disables it in place, to be re-enabled by its own scene — and carried out of that scene it would outlive the unload and meet its own copy when the scene loads again.