One might protect the actions against having a null
callback Action
at the time the action is completed.
So for example when the spin is completed:
if (_totalSpinAmount >= 360f)
{
_isActive = false;
_onActionComplete();
}
if the calling side did
selectedUnit.GetSpinAction().Spin(null);
instead of
selectedUnit.GetSpinAction().Spin(ClearBusy);
We would get an error when the action completed.
So instead one could do this:
if (_totalSpinAmount >= 360f)
{
_isActive = false;
_onActionComplete?.Invoke();
}
But since we’re not just having a bunch of listeners for an event and if onActionComplete
were null
all that might happen is in some situation the game would be missing some animation, some sound effect, or similar polishing details, but this time it’s a crucial element of the code’s flow to have the action inform the action system about being done and clearing the “busy” state, here it should be a good thing to have an error pop up if the delegate invocation fails.