Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AMyAIController::AMyAIController()
- {
- //Initialize BehaviorTreeComponent, BlackboardComponent and the corresponding key
- BehaviorComp = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorComp"));
- BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComp"));
- LocationToGoKey = "LocationToGo";
- }
- void AMyAIController::Possess(APawn* Pawn)
- {
- Super::Possess(Pawn);
- //Get the possessed Character and check if it's my own AI Character
- AAICharacter* AIChar = Cast<AAICharacter>(Pawn);
- if (AIChar)
- {
- //If the blackboard is valid initialize the blackboard for the corresponding behavior tree
- if (AIChar->BehaviorTree->BlackboardAsset)
- {
- BlackboardComp->InitializeBlackboard(*(AIChar->BehaviorTree->BlackboardAsset));
- }
- /*Populate the array of available bot target points
- The following function needs a TArray of AActors, that's why I declared the
- BotTargetPoints as such. When I will need to get an exact point and compare it,
- I will cast it to the corresponding class (ABotTargetPoint)*/
- UGameplayStatics::GetAllActorsOfClass(GetWorld(), ABotTargetPoint::StaticClass(), BotTargetPoints);
- //Start the behavior tree which corresponds to the specific character
- BehaviorComp->StartTree(*AIChar->BehaviorTree);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement