// Called when the game starts or when spawned void AMonsterAIControllerBase::BeginPlay() { Super::BeginPlay(); if (BehaviorTreeAsset) { RunBehaviorTree(BehaviorTreeAsset); } }
void AZanshinAIController::Possess(class APawn* InPawn) { Super::Possess(InPawn); AZanshinBot* Character = Cast<AZanshinBot>(InPawn); if (Character && Character->BehaviorTree) { BlackboardComponent->InitializeBlackboard(*Character->BehaviorTree->BlackboardAsset); BehaviorTreeComponent->StartTree(*(Character->BehaviorTree)); RunBehaviorTree(Character->BehaviorTree); LocationID = BlackboardComponent->GetKeyID("Destination"); } AZanshinDrone* Drone = Cast<AZanshinDrone>(InPawn); if (Drone && Drone->BehaviorTree) { BlackboardComponent->InitializeBlackboard(*Drone->BehaviorTree->BlackboardAsset); BehaviorTreeComponent->StartTree(*(Drone->BehaviorTree)); RunBehaviorTree(Drone->BehaviorTree); LocationID = BlackboardComponent->GetKeyID("Destination"); } }
void AMurphysLawAIController::Possess(APawn* InPawn) { Super::Possess(InPawn); // Reset the blackboard and start ai action logic if (BehaviorTreeAsset != nullptr && InPawn != nullptr) { bPossessPawn = true; // Based on AAIController::RunBehaviorTree implementation, the // AAIController::Blackboard variable should be initialized on success const bool StartedSuccessfully = RunBehaviorTree(BehaviorTreeAsset); if(StartedSuccessfully && Blackboard != nullptr) { // Set initial default values InitializeBlackboardKeys(InPawn); } else { ShowError("Blackboard component should have been created by parent class"); } } }