Server Object Pool Worker

The ServerObjectPoolWorker is responsible for managing a pool of GameObjects on the server side efficiently.

Properties

  • private Dictionary<GameObject, List<GameObject>> poolDictionary: Represents the pool collection.

Methods

  • public GameObject GetPooledObject(GameObject prefab): Retrieves an active GameObject from the pool. If no inactive object is available in the pool, a new object is instantiated, added to the pool, and returned.

  • public void ReturnToPool(GameObject obj): Deactivates a GameObject and returns it to the pool, making it available for reuse. The object is unspawned on the network using NetworkServer.UnSpawn before being deactivated.

  • public void InitializePool(GameObject prefab, int count): Initializes the pool for a specific prefab by instantiating a specified number of objects, deactivating them, and adding them to the pool.

Last updated