Hey,
I´m currently developing an AI in C++ and came to a problem, where I need some help.
My AI should Move and only after it received the “ReceiveMoveCompleted”-Event from my AIController, it should return a EBTNodeResult::Success. So I´m looking for a way in how to achieve
this. The doc of the BTTaskNode is not really helping me. I´m looking for some sort off “Wait until the event was executed to continue your flow”. Hopefully someone will help me out. I´m currently
inspecting the BTTask_MoveTo BP in the source code, but really can`t figuring out, how they achieved some sort of “waiting” inside the ExecuteTask.
EBTNodeResult::Type UBTTWorkMission::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
ownerptr = &OwnerComp;
AAIController* AIOwner = OwnerComp.GetAIOwner();
TScriptDelegate<FWeakObjectPtr> MovementComplete;
const FName name = "FinishedMoving";
MovementComplete.BindUFunction(this, name);
AIOwner->ReceiveMoveCompleted.Add(MovementComplete);
const FName BlackboardKey = "CurrentRoutineGate";
ARoutineGate* Gate = dynamic_cast<ARoutineGate*>(OwnerComp.GetBlackboardComponent()->GetValueAsObject(BlackboardKey));
if (Gate)
{
CurrentWorkOrder = Gate->GetCurrentWorkOrder();
UE_LOG(LogTemp, Warning, TEXT("CurrentWorkOrder assigned executed"))
}
else {
UE_LOG(LogTemp, Warning, TEXT("CurrentWorkOrder not assigned"))
}
//UE_LOG(LogTemp, Warning, TEXT("CurrentWorkOrder: %d"), CurrentWorkOrder.TimeCost)
UE_LOG(LogTemp, Warning, TEXT("BTTWorkMission executed"))
// Executes WorkOrder Logic depending on MissionType
ExecuteWorkOrderLogic(OwnerComp);
MoveToWaypoint(OwnerComp);
// Resets the MissionType to get the next Mission
ResetMissionType(OwnerComp);
// Succeed, when Mission has finnished
// Wait with function execution till Recieve MoveCompleted to return EBTNodeResult::Success
return EBTNodeResult::InProgress;
}