Guys, maybe i’m late, but i found a great, simple and very effective solution that stops behaviour tree work without multithreading.
You just need to open BTTask_Wait class and see that there is no need to recreate a bicycle
I put this code and it suddenly worked
UBTTAttackActor::UBTTAttackActor()
{
NodeName = "Attack Target Actor";
bNotifyTick = true;
}
void UBTTAttackActor::OnGameplayTaskActivated(UGameplayTask& Task)
{
IsWeaponWorkComplete = false;
}
EBTNodeResult::Type UBTTAttackActor::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
SelfActor = Cast<AUCGAIPawn>(OwnerComp.GetBlackboardComponent()->GetValueAsObject(SelfActorKey.SelectedKeyName));
TargetActor = Cast<AUCGBasePawn>(OwnerComp.GetBlackboardComponent()->
GetValueAsObject(TargetActorKey.SelectedKeyName));
TargetActor->GetMovementComponent()->StopMovementImmediately();
UUCGAIWeaponComponent* AIWeaponComponent = Cast<UUCGAIWeaponComponent>(SelfActor->WeaponComponent);
// Subscribe on weapon delegate
AIWeaponComponent->GetWeapon()->OnWeaponWorkCompleteDelegate.AddUObject(this,
&UBTTAttackActor::SetWeaponWorkIsComplete);
// Set the function that must be called in the end
// Starts the weapon work
AIWeaponComponent->AttackAutomaticaly();
// Shows Behaviour Tree that work hasnt done
return EBTNodeResult::InProgress;
}
void UBTTAttackActor::TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
// Checks if weapon attacked, stopped and reloaded
if(IsWeaponWorkComplete)
{
IsWeaponWorkComplete = false;
// Finishing the Task, continue BT workflow
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
}
}
void UBTTAttackActor::SetWeaponWorkIsComplete()
{
// Sets the value that checks in Tick
IsWeaponWorkComplete = true;
}