3 //If our character exists inside the UpdatedActors array, register him 4 //to our blackboard component 5 6 for (AActor* Actor : UpdatedActors) 7 { 8 if (Actor->IsA<AEqsTutCharacter>() && !GetSeeingPawn()) 9 { 10 BlackboardComp->SetValueAsObject(BlackboardEnemyKey, Actor); 11 return; 12 } 13 } 14 15 //The character doesn't exist in our updated actors - so make sure 16 //to delete any previous reference of him from the blackboard 17 BlackboardComp->SetValueAsObject(BlackboardEnemyKey, nullptr); 18 } 19 20 AMyAIController::AMyAIController() 21 { 22 //Components Init. 23 BehaviorTreeComp = 24 CreateDefaultSubobject<UBehaviorTreeComponent>(FName("BehaviorComp")); 25 26 BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(FName("BlackboardComp")); 27 28 AIPerceptionComponent = 29 CreateDefaultSubobject<UAIPerceptionComponent>(FName("PerceptionComp")); 30 31 //Create a Sight Sense 32 Sight = CreateDefaultSubobject<UAISenseConfig_Sight>(FName("Sight Config")); 33 34 Sight->SightRadius = 1000.f; 35 Sight->LoseSightRadius = 1500.f; 36 Sight->PeripheralVisionAngleDegrees = 130.f; 37 38 //Tell the sight sense to detect everything 39 Sight->DetectionByAffiliation.bDetectEnemies = true; 40 Sight->DetectionByAffiliation.bDetectFriendlies = true; 41 Sight->DetectionByAffiliation.bDetectNeutrals = true; 42 43 //Register the sight sense to our Perception Component 44 AIPerceptionComponent->ConfigureSense(*Sight); 45 } 46
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 //If our character exists inside the UpdatedActors array, register him //to our blackboard component for (AActor* Actor : UpdatedActors) { if (Actor->IsA<AEqsTutCharacter>() && !GetSeeingPawn()) { BlackboardComp->SetValueAsObject(BlackboardEnemyKey, Actor); return; } } //The character doesn't exist in our updated actors - so make sure //to delete any previous reference of him from the blackboard BlackboardComp->SetValueAsObject(BlackboardEnemyKey, nullptr); } AMyAIController::AMyAIController() { //Components Init. BehaviorTreeComp = CreateDefaultSubobject<UBehaviorTreeComponent>(FName("BehaviorComp")); BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(FName("BlackboardComp")); AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(FName("PerceptionComp")); //Create a Sight Sense Sight = CreateDefaultSubobject<UAISenseConfig_Sight>(FName("Sight Config")); Sight->SightRadius = 1000.f; Sight->LoseSightRadius = 1500.f; Sight->PeripheralVisionAngleDegrees = 130.f; //Tell the sight sense to detect everything Sight->DetectionByAffiliation.bDetectEnemies = true; Sight->DetectionByAffiliation.bDetectFriendlies = true; Sight->DetectionByAffiliation.bDetectNeutrals = true; //Register the sight sense to our Perception Component AIPerceptionComponent->ConfigureSense(*Sight); }