Destroy or Pool Object
v1.0
Last updated
v1.0
Last updated
The DestroyOrPoolObject
class will automatically put objects back into the Object Pool. This is very useful for things that are created by Projectiles, but aren't themselves part of the Projectile.
The demo scenes often make use of this with "Impact" and "Muzzle" particles. These Prefabs
are brought into the scene by the Projectile Collision Behaviors, but are separate objects. The Projectile Power Destroy class allows them to put themselves back into the pool when they're done.
This is the amount of time before the object is destroyed after the RemoveGameObject()
method is called.
When true, the RemoveGameObject()
method will be called as soon as the Projectile
is set. Generally this is immediate, meaning the object will be destroyed in TimeToDestroy
time.
If you want to disable specific objects (children of this object) immediately, prior to the object being destroyed, you can add them to this List<>
.
The objects in the List<>
will be disabled with this delay -- often you want this to be non-zero, so that those objects have a chance to "start" before they are disabled.
Reenable Them On Enable
When true, the objects in the List<>
will be enabled whenever the object with this component on it is enabled. Otherwise, they will remain disabled. Generally this should be true
.
The SetProjectile()
method triggers the entire operation.
The Projectile Utilities class has a ProjectilePowerDestroySetProjectile()
extension method for GameObject
which takes in a Projectile
, and will call the SetProjectile()
method with that value.
This method will return false if the GameObject
does not have a ProjectilePowerDestroy
component.
Any Behavior which spawns an object should call this method on the spawned object, to ensure that the object is used with the Object Pool appropriately. In the example below, the SpawnObjectOnDestroy
Behavior will spawn an object using this pattern.
The DestroyOrPoolObjectWithFade
class adds additional options to fade common particle components including the particle materials (alpha), audio, lights, trail renderers, and line renderers. Each can be toggled on and off, and you can also choose to include children of this object or not.
The values will be reset to their start values when the object is re-enabled.
The script requires the use of a Projectile
because the "Destroy" or "Pool" logic is determined by the logic assigned to the Projectile
.
This class has virtual members, meaning you can create an override that behaves differently, allowing you to make use of the logic with your own system, perhaps one which does not require a Projectile
, or requires another object unique to your project.