Hello,
I’m having a problem getting my AI to move properly. What seems to be happening is that the AI doesn’t wait for the MoveTo() task to finish before moving on. I’ve included my C++ method below that runs the task. I built the blackboard and behavior tree in the editor and only switched to C++ for this single task.
I also have the same problem with the MoveToLocation node in blueprints. Am I just missing some sort of thread lock call?
Thanks!
EBTNodeResult::Type UFilmCarTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) {
m_blackboard = OwnerComp.GetBlackboardComponent();
AStaticMeshActor* Car = dynamic_cast<AStaticMeshActor*> (m_blackboard->GetValueAsObject("CarToFilm"));
FVector CarLoc = Car->GetActorLocation();
FBox CarBounds = Car->GetComponentsBoundingBox();
AAIController* AI_con = OwnerComp.GetAIOwner();
APawn* AI_pawn = AI_con->GetControlledPawn();
FVector CameraLoc = AI_pawn->GetActorLocation();
FVector ClosePoint = CarBounds.GetClosestPointTo(CameraLoc);
FVector* Path = 0;
genPath(CarBounds, ClosePoint, Path);
EPathFollowingRequestResult::Type result;
for (UINT i = 0; i < 60; ++i) {
FAIMoveRequest moveTarget(Path[i]);
moveTarget.SetAcceptanceRadius(10.0f);
result = AI_con->MoveTo(moveTarget);
}
delete[] Path;
if (result == EPathFollowingResult::Type::Success) return EBTNodeResult::Succeeded;
return EBTNodeResult::Failed;
}