I’ve been trying to set up a basic Enemy class, and I wanted to start by the minimal functionality: automatically moving it from one point to another.
tl;dr:
I cannot make an AI controlled pawn to move to the goal location. It will simply stand frozen, not even reproducing the animation from the animation instance blueprint I assigned to it.
Things that I’ve checked/tried:
- AIController successfully possesses the pawn.
- Checked character’s movement component, everything seems OK.
- Navigation Mesh Bounds Volume placed, and generated navigation mesh includes both the pawn and the goal location.
- Erasing and re-placing both the NavMesh Bounds Volume and the Enemy in the level doesn’t do the trick.
- MoveTo() seems to find a path between the pawn and the goal location.
Now, a more detailed break-down of what I’ve already tried:
I started with the simplest setup I could think of: directly calling MoveTo onon a method from the Enemy’s controller:
void AEnemyAIController::DebugMoveToLocation()
{
bDebugEventScheduled = false;
UE_LOG(LogTemp, Warning, TEXT("Debug MoveTo locaiton function called"))
if (GetPawn() && TargetPawn)
{
AEnemy* enemy = Cast<AEnemy>(GetPawn());
if (enemy)
{
FAIMoveRequest MoveRequest;
MoveRequest.SetGoalActor(TargetPawn);
MoveRequest.SetAcceptanceRadius(10.0f);
FNavPathSharedPtr NavPath;
MoveTo(MoveRequest, &NavPath);
if (NavPath)
{
if (NavPath->GetPathPoints().Num() > 0)
{
for (auto pt : NavPath->GetPathPoints())
{
DrawDebugSphere(GetWorld(), pt, 20.f, 12, FColor::Red, true);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("NO PATH FOUND (path had 0 points)"))
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("NO PATH FOUND (path was NULL)"))
}
}
}
}
This is how TargetActor
is initialized:
void AEnemyAIController::BeginPlay()
{
Super::BeginPlay();
TargetPawn = UGameplayStatics::GetPlayerPawn(this, 0);
}
And this is how I set a timer to call to DebugMoveToLocation()
every 5 seconds:
// Called every frame
void AEnemyAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!bDebugEventScheduled)
{
if (GetPawn())
{
GetPawn()->GetWorldTimerManager().SetTimer(DebugTimer, this, &AEnemyAIController::DebugMoveToLocation, 5.0f);
}
bDebugEventScheduled = true;
}
}
It seems to success in finding the path, but not when moving the enemy, as you can see from Visual Logger:
Any ideas of what I’m doing wrong here?
Thanks in advance!