Advertisement
orfeasel

AI Controller Source

Dec 31st, 2015
20,986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. AMyAIController::AMyAIController()
  2. {
  3.     //Initialize BehaviorTreeComponent, BlackboardComponent and the corresponding key
  4.  
  5.     BehaviorComp = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorComp"));
  6.  
  7.     BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComp"));
  8.  
  9.     LocationToGoKey = "LocationToGo";
  10.  
  11. }
  12.  
  13. void AMyAIController::Possess(APawn* Pawn)
  14. {
  15.     Super::Possess(Pawn);
  16.  
  17.     //Get the possessed Character and check if it's my own AI Character
  18.     AAICharacter* AIChar = Cast<AAICharacter>(Pawn);
  19.  
  20.     if (AIChar)
  21.     {
  22.         //If the blackboard is valid initialize the blackboard for the corresponding behavior tree
  23.         if (AIChar->BehaviorTree->BlackboardAsset)
  24.         {
  25.             BlackboardComp->InitializeBlackboard(*(AIChar->BehaviorTree->BlackboardAsset));
  26.         }
  27.  
  28.         /*Populate the array of available bot target points
  29.         The following function needs a TArray of AActors, that's why I declared the
  30.         BotTargetPoints as such. When I will need to get an exact point and compare it,
  31.         I will cast it to the corresponding class (ABotTargetPoint)*/
  32.         UGameplayStatics::GetAllActorsOfClass(GetWorld(), ABotTargetPoint::StaticClass(), BotTargetPoints);
  33.  
  34.         //Start the behavior tree which corresponds to the specific character
  35.         BehaviorComp->StartTree(*AIChar->BehaviorTree);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement