Every ability and effect moves through a defined set of lifecycle stages. This page breaks down each stage in detail.
Lifecycle
Every ability must be defined and activated from somewhere. In the following example, assume it's defined in a generic ability_manager class, but you can substitute the concepts to fit your own implementation.
During game initialization, the ability manager is created along with all ability members.
During gameplay, abilities await the manager's activation trigger.
On ability activation:
The ability manager creates the ability context and populates it with the required data.
The manager calls
Use()with a reference to the context and the entity that is activating the ability.Internally,
Use():Calls
CanUse()to validate the ability activation. If invalid, the activation stops here. Otherwise, it continues.Calls
MakeContext()to create a copy of the context for the effect component.Calls
MakeAbility()to create the effect entity with the effect component attached.Adds the effect to the
ActiveEffectslist.Returns the newly created effect to the manager.
The ability context is destroyed. The context copy on the effect component persists until ability deactivation.
The effect component's
OnBeginUse()callback triggers.The ability's
BeginUseEvent()broadcasts.
Each active effect component runs asynchronous logic in
OnSimulate()until deactivation viaEndUse()orCancel().If
Cancel()is called,CanCancel()is called to validate. If the givencancel_reasonis valid,EndUse()is called. Otherwise, the simulation continues.If
EndUse()is called explicitly or by cancellation, the ability begins deactivation.
On ability deactivation:
The effect component's
OnEndUse()callback triggers.The ability's
EndUseEvent()broadcasts.Internally,
EndUse():Removes the effect from the ActiveEffects list.
Destroys the effect entity and associated objects.
At the end of the game, the
abilityis destroyed with other persistent objects.
Object Lifetime Reference
| Type | Lifetime |
|---|---|
| Persistent |
| Per Activation and Effect Lifetime |
| Transient |
| Effect Lifetime |