Skip to content

leventeren/Addressable-Pool

Repository files navigation

Unity Addressables Pooling System

A lightweight and efficient pooling system built on top of Unity Addressables.
It allows you to load, reuse, and release assets dynamically while minimizing memory overhead and loading time.


📘 Overview

This system combines Addressables and Object Pooling patterns to achieve:

  • ✅ Dynamic loading of Addressable assets
  • ✅ Reuse of instantiated objects without destroying them
  • ✅ Memory-efficient lifecycle management
  • ✅ Safe handling of AsyncOperationHandles (no invalid handle exceptions)
  • ✅ Ready for both local and remote Addressables catalogs

🧱 System Architecture

AddressablePoolManager

  • Manages all pools
  • Handles loading & release

ObjectPool

  • Stores inactive objects
  • Reuses prefab instances

Pool Objects

  • Used in scene
  • Returned to pool

⚙️ Installation

  1. Clone this repository into your Unity project’s Assets folder:
    git clone https://github.com/yourname/Unity-Addressables-Pooling.git
    
  2. Ensure you have Addressables installed:
  • In Unity Editor: Window → Package Manager → Addressables
  1. Build your Addressables groups:
  • Open Window → Asset Management → Addressables → Groups
  • Create your groups and mark prefabs with unique addresses

Example Usage

Spawning Addressable Objects

public class ExplosionSpawner : MonoBehaviour
{
[SerializeField] private AddressablePoolManager poolManager;

    private async void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = new Vector3(Random.Range(-3f, 3f), 0, 0);
            GameObject explosion = await poolManager.Spawn("ExplosionPrefab", pos, Quaternion.identity);

            // Return object to pool after 2 seconds
            StartCoroutine(ReturnAfterDelay(explosion));
        }
    }

    private IEnumerator ReturnAfterDelay(GameObject obj)
    {
        yield return new WaitForSeconds(2f);
        poolManager.Despawn("ExplosionPrefab", obj);
    }
}

🧠 Core Classes

AddressablePoolManager.cs

Handles all pool creation, asset loading, and safe handle releasing.

ObjectPool.cs

Stores inactive instances for reuse. Automatically creates new ones when needed.

🚫 Common Pitfalls

Issue Cause Solution Attempting to use an invalid operation handle Handle released too early Check handle.IsValid() before releasing Duplicated prefab loads Missing address check Cache pools by address key Memory leaks Never releasing Addressables Always release handles in OnDestroy()

🧰 Recommended Enhancements

Async Preloading: Load frequently used assets on game start

Auto Return: Auto-release objects after use (timed or event-based)

Remote Catalogs: Integrate with CDN for live updates

Editor Debug Tools: Add pool visualization in inspector (via Odin or custom editor)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages