Note: This documentation is for the old 0.9.0 version of A-Frame. Check out the documentation for the current 1.5.0 version
The pool component allows for object pooling. This gives us a reusable pool of entities to avoid creating and destroying the same kind of entities in dynamic scenes. Object pooling helps reduce garbage collection pauses.
Note that entities requested from the pool are paused by default and you need
.play() in order to activate their components’ tick functions.
For example, we may have a game with enemy entities that we want to reuse.
<a-scene pool__enemy="mixin: enemy; size: 10"></a-scene>
var el = sceneEl.components.pool__enemy.requestEntity();
|Selector to store pooled entities. Defaults to the scene.
|Grow the pool automatically if more entities are requested after reaching the
|Mixin required to initialize the entities of the pool.
|Number of preallocated entities in the pool.
Request one of the available entities in the pool. Will return
log a warning if
grow is set to
false and you have exhausted the pool.
Relinquish an entity back to the pool. Will log a warning if you attempt to return an entity that did not belong to this pool.