Skip to main content

FactoryAsyncPooled<TConcrete, TInterface>

An abstract class in Alta.VContainerLayer.Runtime, the global namespace.

Async Addressables prefab factory that pools its instances. Spawn reuses a despawned instance when there is one; Dispose destroys every instance it made.

Constructors​

MemberWhat it is
protected FactoryAsyncPooled()Creates a FactoryAsyncPooled with default values.

Fields​

4 private and internal fields
MemberWhat it is
private readonly HashSet<TConcrete> allConcreteEvery instance this factory has created, pooled or not, destroyed in Dispose.
private readonly List<AsyncOperationHandle> assetHandlesAddressables load handles taken so far, released in Dispose.
private readonly Stack<TInterface> poolStack of despawned instances waiting to be reused.
private AssetReference prefabReferenceThe Addressables reference of the prefab this factory instantiates.

Methods​

MemberWhat it is
void Despawn(TInterface instance)Calls OnDespawn on the instance and pushes it back onto the pool for reuse.
override void Dispose()Destroys the GameObject of every instance still alive, releases the Addressables handles, then disposes tracked instances.
protected void Construct(AssetReference prefabReference)Injection method that stores the Addressables prefab reference to load.
protected async Task<TInterface> Spawn()Returns a pooled instance if one is free, otherwise creates a new one. Does not call OnSpawn; the typed subclasses do.
3 private and internal methods
MemberWhat it is
private async Task<TInterface> Create()Loads the prefab, instantiates it through the container, records it in allConcrete and tracks it for disposal.
private Task<GameObject> LoadAsset()Starts loading the prefab through Addressables, keeps the handle for release, and returns the load task.
private bool TryGetFromPool(out TInterface instance)Pops a despawned instance from the pool if any are waiting.