Custom Pooling Systems

Creating a custom Pooling System

While the Runtime Spawner automatically integrates with the Megacrush Object Pool, you can replace the pooling layer entirely if your project already has its own pooling or streaming system.


1. Replace the Pool Adapter

Each factory (SinglePlayer, Fusion, PUN) accepts an IObjectProvider or IPoolAdapter interface. You can provide your own implementation that fulfills the same contract.

Example: Custom Provider

public class AddressablePoolProvider : IObjectProvider
{
    public GameObject Spawn(GameObject prefab, Vector3 pos, Quaternion rot)
    {
        return Addressables.InstantiateAsync(prefab.name, pos, rot).WaitForCompletion();
    }

    public void Despawn(GameObject instance)
    {
        Addressables.ReleaseInstance(instance);
    }
}

Then inject it into your own factory:

public sealed class AddressableFactoryAsset : ObjectFactoryAsset
{
    public override IObjectFactory Create()
    {
        return new SinglePlayerPoolFactory(new AddressablePoolProvider());
    }
}

This completely replaces the built-in pooling behavior while retaining spawner logic.


2. Guidelines for Custom Pool Systems

Goal
Recommendation

Performance parity

Avoid Instantiate/Destroy; cache and reuse objects.

Compatibility

Implement IObjectProvider or wrap your pool in an adapter.

Networking

For replicated games, ensure the provider and network API both manage consistent lifecycles.

Diagnostics

Log Spawn/Despawn events for debugging parity with built-in pool.


3. Hybrid Approaches

You can mix pools per system:

  • Static actors → Addressables / ECS instantiation.

  • Dynamic enemies → Object Pool Adapter.

  • Networked units → Fusion or PUN providers.

This allows maximum flexibility without changing your spawner setup.


✅ Summary

Pooling is the backbone of Runtime Spawner’s performance and scalability. Whether you use the built-in system or bring your own, the integration point is always the same — the Factory’s Provider Layer.

Key takeaway: Swap the provider, not the spawner. Your spawn logic remains identical.

Last updated