AI Controller stops following character

I’m slowly working on a third person action RPG style game and I’ve just started looking at AI.

So far I have an enemy class that inherits from ACharacter and to get things started I wrote a simple function to make the enemy follow the player character (PlayerCharacter below is a pointer to ACharacter*), using the AIController like so;

void AEnemy::MoveToPlayer()
{
	if (AIController && PlayerCharacter)
	{
		FAIMoveRequest MoveRequest;
		MoveRequest.SetGoalActor(PlayerCharacter);
		MoveRequest.SetAcceptanceRadius(5.0f);
	
		FNavPathSharedPtr NavPath;

		AIController->MoveTo(MoveRequest, &NavPath);
	}
}

This works great, except when the player character jumps over something. As this is a third person game, I have jumping and if I jump over something that doesn’t have a nav mesh then the enemy character stops moving.

Looking through the docs I found AIController->GetMoveStatus() which returns EPathFollowingStatus::Idle once the character has stopped following the player.

I was wondering if there is a way to set up the enemy so it would continue once my player is back on the navmesh, or if not what’s the best way to handle this?

I was thinking of adding a check in tick on the lines of;

if (AIController->GetMoveStatus() == EPathFollowingStatus::Idle) MoveToPlayer();

but that seems like a slow brute force option that might cause problems if there are 10 or more characters all suddenly trying to path to the player at the same time.

Can anyone suggest the best way to keep my enemy’s moving?

There is not really a way. We use behaviour trees, and the ai moves, if he cant path, then a small delay, then he tries to path again to his intended target.

As soon as the path following component goes idle, you have to call MoveTo again.

If you want to go pure C++, you need to monitor OnMoveCompleted and determine if you need to path again. If the result is Success, then the agent made it to its target, any other is a failure to reach its target.

Thanks for the answer. I will have to dig a little deeper into the AI controller, but I think this answers my question for now.