Function overriding in states
One question we might ask at this point is how can we have more than one Tick
function in our class? Don't they interfere with each other? With states, each one can have functions operate differently, as with our use of Tick
and how it changes depending on what state we're in. Functions can be changed in each state or ignored completely. We left TakeDamage
alone, for instance, although we could have made an empty version inside the Fleeing
state to keep the enemies from taking damage as they fled.
Taking a look at our updated AwesomeEnemy
class, we can also see that functions don't even need to be in a state. With our TakeDamage
function, as it's not in a state and not overridden in any state, it will operate the same way no matter what state the actor is in.
Red state, blue state, no state, new state?
Let's take a look at function overriding in states so we can understand how it works.