Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pool Management System

This project implements a flexible and efficient object pooling system for Unity, designed to improve performance by reusing game objects rather than continuously creating and destroying them. The system provides a clean API for managing object pools with customizable initialization, spawning, and termination behaviors.

Table of Contents

  1. Overview
  2. Core Components
  3. Features
  4. Getting Started
  5. Usage
  6. Events

Overview

The Pool Management System offers:

  • Automatic object initialization and management
  • Configurable pool sizes and overflow handling
  • Event-driven architecture for lifecycle management
  • Editor-friendly components with Unity Inspector support
  • Flexible spawn and despawn controls

Core Components

Pool.cs

The Pool component manages collections of pooled objects and handles their lifecycle.

Key Features:

  • Configurable initial pool size
  • Two overflow handling strategies:
    • Expandable: Creates new objects when needed
    • Recyclable: Reuses oldest active objects
  • Comprehensive event system for pool operations
  • Editor-friendly debug operations

Configuration Options:

public PoolObject poolObject;        // Prefab to pool
public int numToInitialize = 10;     // Initial pool size
public bool initializeOnStart = true; // Auto-initialize on Start
public OverflowType overflowType;    // Overflow handling strategy

PoolObject.cs

The PoolObject component represents individual pooled objects and manages their state.

Key Features:

  • Automatic pool reference management
  • Event-driven lifecycle hooks
  • Context menu operations for testing
  • Clean separation of concerns

Features

  1. Automatic Pool Management

    • Automated initialization of pool objects
    • Smart handling of object reuse
    • Memory-efficient object recycling
  2. Flexible Overflow Handling

    • Expandable pools grow automatically
    • Recyclable pools reuse existing objects
    • Configurable through Unity Inspector
  3. Event System

    • Initialize events
    • Spawn events
    • Despawn events
    • Terminate events
  4. Debug Support

    • Context menu operations
    • Clear object state management
    • Easy testing through Unity Editor

Getting Started

  1. Create a new prefab with your desired component(s)
  2. Add the PoolObject component to your prefab
  3. Create an empty GameObject in your scene
  4. Add the Pool component to the GameObject
  5. Assign your prefab to the poolObject field
  6. Configure initial pool size and overflow behavior

Usage

Basic Setup

// Get reference to pool
Pool pool = GetComponent<Pool>();

// Initialize with default size
pool.Initialize();

// Or initialize with custom size
pool.Initialize(20);

Spawning Objects

// Spawn single object
pool.Spawn(1);

// Spawn multiple objects
pool.Spawn(5);

// Spawn specific pool object
pool.Spawn(poolObject);

Despawning Objects

// Despawn a specific object
pool.Despawn(poolObject);

Termination

// Terminate entire pool
pool.Terminate();

// Terminate specific object
pool.Terminate(poolObject);

Events

The system provides several UnityEvents for lifecycle management:

Pool Events

  • OnInitialize: Called when the pool is initialized
  • OnSpawn: Called when an object is spawned
  • OnDespawn: Called when an object is despawned
  • OnTerminate: Called when the pool or object is terminated

PoolObject Events

  • events.OnInitialize: Called when the object is initialized
  • events.OnSpawn: Called when the object is spawned
  • events.OnDespawn: Called when the object is despawned
  • events.OnTerminate: Called when the object is terminated

These events can be hooked up through the Unity Inspector or via code to implement custom behavior at various stages of the object lifecycle.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages