Time for action – BeginState
BeginState
and EndState
are both declared in Object.uc
, and like other functions, they don't necessarily have to be used inside a state, although that's where they are most useful. BeginState
is called when an actor enters any state, before any of that state's code is run. This makes it useful for running any set-up code that the state needs. EndState
is run right before an actor leaves a state and lets us do any cleanup or other changes we need to at that point. Both of these functions are called during the chain of events when GoToState
is called. EndState
is called on the state that's being left and BeginState
on the state that the actor is going into.
Let's see how we can use these functions in our AwesomeEnemy
class.
The easiest thing we could do to try out these functions is change the enemy's appearance based on what state it's in, so let's try that. First, let's declare a few materials to use for the various states:
var Material SeekingMat, AttackingMat...