This article will continue into the Agent AI State logic, focusing on the Chase Enumeration State.

I'll create the properties and functions for Chase Target state.

None

Next, I'll set the agent state to Chase when pawn sensed is discovered.

None

I'll then declare the character movmenet component to set the speed.

None

Get access to the Character Movement library.

None

Set the move component and speed, here I use the auto property to ensure the move component is initialized. Additionally, this can be checked by just GetCharacterMovement()->speed variable.

None

Set the chase target and move to target (chase target).

None

Define the agent states in event tick function, by default I want to have th AI agent patrol before being in a chase state.

None

Next, check if the chase target is valid and check if the chase target is in reachable range then return to patrol if out of chase target range.

None

In the details panel, I'll set the chase target range.

None

I use a "dummy character" to see if the AI will target the standing actor. It starts chasing then goes into patrol to next patrol target.

None

In the Move Target function, I'll get the actor location to move to within an acceptable range.

None

The Set Goal Actor will be assigned to the new target instead of patrol target.

None

Ensure the Player has a tag component string called Player.

None

In the patrol target state in the tick function, call chase target.

None

If the Ai agent is patrolling or out of range, return to patrol state.

None

In the pawn sensed function, I'll check if chase target is active and directly check if the pawn sense component is valid at low level, and get the actor location.

None

Next, I'll make sure to compile source code and set the Chase Target and Chase Range variables.

None

I'll test to ensure the code is working, and here the chase range is too low.

None

I'll bump the chase range to 500 and see if that works.

None

And now when the AI agent is in range of the chase target, it chases the player, and will then patrol back to it's next target when chase target is no longer valid.

None

And that's all for Chase State enumerations in Unreal and C++.

Stay tuned for more.

Thanks,

Zac B.