Skip to content

Actor Pooling

It's very common for a combat system to require spawning and destroying multiple actors. Projectiles and Cast actors are very common use cases where actors are frequently spawned and destructed in short intervals.

To mitigate the cost of constantly spawning/destroying actors during gameplay, an Actor Pool was introduced to the Combat System, that can prepare a predefined amount of instances of actors frequently used by a combatant.

Summary: Actor Pooling
  • Represented by the NinjaCombatActorPoolComponent, assigned to each combatant using the pool.
  • Combatants must provide their pools via CombatPoolProviderInterface.
  • The pool supports any actor implementing the CombatPoolableActorInterface.
  • The NinjaCombatPoolableActor is a default implementation that supports replication.
  • Projectiles and Cast actors are poolable and can be added to a pool's configuration.
  • The pool is replicated and pooled actors behave as if they were placed in the map.

The Actor Pool Component

Each combatant has its own Actor Pool, represented by the NinjaCombatActorPoolComponent. You can configure all actors that will be pooled and how many instances will be available.

It's important that combatants using an Actor Pool implement the CombatPoolProviderInterface, providing the component, so external functionalities can quickly retrieve and use the pool, such as the Projectile Request.

Poolable Actors

Poolable Actors are primarily defined by the CombatPoolableActorInterface. This means that any actor implementing this interface can be added to the Actor Pool Component.

If possible, and if you are building a multiplayer game, then it's recommended that, instead of implementing that interface, you extend from NinjaCombatPoolableActor. This base actor not only implements the Poolable Actor interface, but it's configured in a way that it supports networking and replication, as if the actor was originally placed in the map.

The Actor Pool Component and the base Poolable Actor can work together to reduce the initial network usage that would be necessary to replicate many actors being spawned at the same time, when preparing the pool.

Current Support

Right now, Projectiles and Cast actors are supported by default.