Composite Killables

Composite Killables are prefabs that have a top-level Game Object with a Killable script on it, and one or more sub-prefabs that also have Killable scripts on them. There are settings to allow the top-level Game Object to be invincible (and optionally disable its Collider) while any child Killables are still alive. You can also have the sub-prefabs also have sub-prefabs with Killables on them - any number of Hierarchy levels are supported. Constructing a prefab like this can make huge boss enemies where you have to kill all the turrets or other moving parts before you can take down the boss itself. There is an example Scene called "5.CompositeKillables" that shows off this feature.

 

Some important tips and notes about Composite Killables:

     
  1. Composite Killables cannot be respawned or returned to Pool Boss for reuse if one or more of its child Killables have been despawned or killed. Instead, the Composite Killable Game Object will automatically be set to inactive when it is despawned or killed if that is the case. The reason is that Unity does not provide a way to revert a prefab instance during runtime currently. This isn't normally a problem as prefabs like this aren't reused very often, just be aware of it. So, make sure to not turn on any Despawn Trigger checkboxes on the child Killables (like invisible) as it can screw things up.
  2.  
  3. If you want to make multiple levels of destruction of sub-Killables, make sure the "Keep Same Parent" box is checked on the Death Prefab Settings of that sub-Killable, which is the default.
  4.  
  5. If you spawn (through script) and parent another child under a Killable, it will not automatically be registered with the parent. You will need to call the RegisterChildKillable method on the parent Killable class manually. We could add this code to be automatic but it would slow down performance a lot for an edge case.