Skip to main content

Module Intro

Important Attention Reminder

Coding Style wiki​


Basic Instructions​

A simple GameObject object pool with support for asynchronous across-frames loading (load balancing). Attach the NodePool component to configure the pool source, initial size, auto growth (Auto Put), and max size limiting (Max Size).

  • Version: v1.0.2 (com.michaelo.oxgkit.poolsystem)
  • Namespace: OxGKit.PoolSystem

Attention This module depends on LoggingSystem for log output (logger name: OxGKit.PoolSystem.Logger); installing it first is recommended.


Application Description​

NodePool Inspector Setup​

  • Attach the component to a scene node via Add Component -> OxGKit -> PoolSystem -> NodePool (that node becomes the pool's container node), then configure the following in the Inspector:
    • Source options
      • go (Source GameObject): The source object to pool (required).
    • Pool options
      • initializeOnStart: Whether to initialize the pool automatically on Start (enabled by default).
      • initSize: The initial size of the pool.
      • initLoadAcrossFrames: Enables across-frames loading (load balancing) during initialization.
      • initDelayFrameAfterSpawnCount, initDelayFrame: During initialization, after spawning N objects, delay M frames before continuing.
    • Auto put options
      • autoPut: Whether to auto-create objects when the pool runs dry.
      • autoPutSize: The increment count for each auto-create operation.
      • autoPutLoadAcrossFrames, autoDelayFrameAfterSpawnCount, autoPutDelayFrame: Across-frames loading settings for auto-put.
    • Limit options
      • maxSize: The pool size cap. 0 or -1 means unlimited; when > 0, both initSize and autoPut growth are restricted.

Important Source GameObject must not be null — initializing the pool without a source throws an ArgumentNullException. Also, one NodePool pools exactly one source object; create a separate NodePool per object type.

Across-Frames Loading (Load Balancing)​

With initLoadAcrossFrames / autoPutLoadAcrossFrames enabled, instantiation is spread over multiple frames (powered by UniTask) in a "spawn N objects, then delay M frames" pattern, avoiding hitches caused by mass Instantiate calls in a single frame. Use IsLoadFinished() to check whether loading has finished.

Auto Growth (Auto Put)​

With autoPut enabled, when Get() finds no available object in the pool, it auto-creates autoPutSize objects (the growth count is restricted by maxSize); even with across-frames loading enabled, the first object is still created in the same frame and returned immediately. Without autoPut, Get() on an empty pool returns null.

Size Limiting (Max Size)​

Setting maxSize > 0 caps the total pool size (both initSize and autoPut growth are restricted); a Put() beyond the cap destroys the object directly and logs a reminder.

Reminder The pool count tracks idle objects (Get() decrements it, Put() increments it); size maxSize based on peak concurrent usage.


Simple Usage​

Get & Put​

using OxGKit.PoolSystem;
using System.Collections.Generic;
using UnityEngine;

public class NodePoolDemo : MonoBehaviour
{
// Assign the scene's NodePool in the Inspector (Source GameObject configured)
public NodePool objPool;

// Buffer for objects taken from the pool
private Queue<GameObject> _objs = new Queue<GameObject>();

private void Start()
{
// Manually initialize the pool (with initializeOnStart checked, it auto-initializes on Start)
this.objPool.Initialize();
}

public void GetFromPool()
{
// Get from the pool with a parent (returns null if the pool is empty and autoPut is off)
var go = this.objPool.Get(this.transform);
if (go != null)
this._objs.Enqueue(go);
}

public void PutIntoPool()
{
// Put back into the pool when done
if (this._objs.Count > 0)
this.objPool.Put(this._objs.Dequeue());
}
}

Check Pool State​

// Whether across-frames loading has finished
bool isLoadFinished = this.objPool.IsLoadFinished();

// Current idle count in the pool
int count = this.objPool.Count();

// Clear the pool (cancels pending loading and destroys pooled objects)
this.objPool.Clear();

[Refer to Example]


Installation​

Install via git URL
Add https://github.com/cout-m6o/OxGKit.git?path=Assets/OxGKit/PoolSystem/Scripts to Package Manager

Dependencies (install manually)

Samples (Package Manager -> Samples)


Module API​

  • Runtime

Demo​

PoolSystem Demo