Skip to content

PoolObject

Attach to pooled prefabs to handle the activation/deactivation lifecycle and self-return logic.

Namespace: Jungle.Objects
Inherits: JungleBehaviour → MonoBehaviour

Overview

PoolObject is the per-instance component for objects in a GameObjectPool (the reserve a PooledObjectCreator manages). It manages its own lifecycle: acquire activates the GameObject, release deactivates it. Optional IProcess hooks run on acquire and release for visual effects or setup. An optional IPoolReturnTrigger allows the object to return itself to the pool automatically.

The pool creates each instance switched off, so nothing on it runs until it first leaves the pool: a process that starts on enable plays when the object is handed out, not when the pool fills. Put one-time setup that should happen at creation in createdProcess.

Properties

Property Type Description
returnTrigger IPoolReturnTrigger Optional trigger that determines when the object returns to the pool.
createdProcess IProcess Optional process to run once, when the pool creates this object. The object is still switched off.
outOfPoolProcess IProcess Optional process to run when acquired from the pool.
backToPoolProcess IProcess Optional process to run when released back to the pool.

Runtime API

Member Type Description
Pool GameObjectPool The pool this object belongs to. Internal; read it through the owning creator.
IsAcquired bool Whether this object is currently in use.
OnAcquired event Action<PoolObject> Fired on acquire.
OnReleased event Action<PoolObject> Fired on release.

Methods

Method Description
Acquire(Action) Mark as in-use, activate, arm return trigger, run out-of-pool process.
Release(Action) Return to pool, disarm trigger, run back-to-pool process, deactivate.
ResetState() Virtual method for subclass-specific reset logic.

See Also