Skip to content

Documentation

Dawid Slabkowski edited this page Dec 12, 2023 · 6 revisions

Table of context


Start

How to create an object pool.

To create an object pool, simply add an ObjectPool component to any actor or use the Add Component by Class function.
image image

Initial settings

  • SpawnPoolObjectsOnBeginPlay - Specifies whether the pool should be filled at BeginPlay time. If false you have to fill it yourself during the game using AddActorsToPool function.
  • PoolActorClass - Specifies what class of actors to be in the pool. It cannot be changed during the game.
  • InitialPoolSize - If the variable SpawnPoolObjectsOnBeginPlay is true, as many actors will be created as this variable is set to.
    image

Functions

  • Add Actors to Pool
    Adds the specified number of actors to the pool.
    image

  • Spawn Actor from Pool
    Returns and "spawns" an actor from the pool. If the pool is empty or all in use and the input variable "SpawnActorIfPoolIsEmpty" equals false the function will return nullptr.
    This function: show an actor, enable collisions, and turns on tick.
    image

  • Return Actor to Pool
    Function that returns actor back to the pool.
    This function: hide an actor, disable collisions, and turns off tick.
    image

  • Get Active/Inactive Actors from Pool
    Functions that returns array of active/inactive actors in the pool.
    image

  • Get Pool Size
    Return total number of actors in the pool.
    image

  • Has Pool Free Actor
    Returns whether the pool has at least one free actor.
    image

  • Is Actor in Use
    Is given actor used by this pool right now?
    image


Dispatchers

  • On Actor Spawned from Pool
    Dispatcher, which is called each time an actor is pulled from the pool.
    image

  • On Actor Returned to Pool
    Dispatcher, which is called each time an actor returns to the pool and becomes inactive.
    image


Interface

Interface can be added to the actor that is used in the pool. Called when the actor is Spawned/Despawned from the pool.
image