Time for action – Using state detection functions
The first thing that would be handy to know is: what state are we in? We can use a function called GetStateName
to find this out.
Let's put a
PostBeginPlay
function back in ourAwesomeEnemy
class, and use it to start a repeating timer:function PostBeginPlay() { SetTimer(0.5, true, 'WhatState'); }
Now, let's create the
WhatState
function:function WhatState() { `log(GetStateName()); }
Now we're ready to test. Compile the code and run the game, then exit and check the log:
[0009.81] ScriptLog: Seeking [0010.30] ScriptLog: Seeking [0010.76] ScriptLog: Attacking [0011.25] ScriptLog: Attacking
Working great!
Now how can we use this to our advantage? Well, let's take a look at the material-changing functionality we're using in
AwesomeEnemy
. It seems a bit inconsistent with what's going on with that actor's movement. It turns blue when attacking, then back to red for seeking. However, as we added that one-second delay before it starts moving again...