# AI Perception (C++) Not Firing

**URL:** <https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912>\
**Category:** AI\
**Tags:** UE4-12, unreal-engine, question, CPP\
**Created:** [July 4, 2016, 4:25pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912 "2016-07-04T16:25:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_32265baf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_32265baf](https://forums.unrealengine.com/u/anonymous_user_32265baf)\
**Post date:** [July 4, 2016, 4:25pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/1 "2016-07-04T16:25:32Z")

</div>

I have already read the Quick AI Perception Guide and surfed through all the tutorials regarding how to set up the AI Perception in C++. Nothing seems to work.

I have managed to only make it work on Blueprint but NOT in C++.

Below is my code:

BaseCharacter.h // Custom Class

```
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Senses)
class UAIPerceptionComponent* PerceptionComponent;
    
UPROPERTY(BlueprintReadWrite, Category = Senses)
class UAISenseConfig_Sight* SightConfig;

UFUNCTION()
void UpdatePerception(TArray<AActor*>ActorsInSight);

```

BaseCharacter.cpp

```
ABaseCharacter::ABaseCharacter()
{
    // ....
    PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AI Perception Component"));
    SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("AI Sight Config"));
    PerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &ABaseCharacter::UpdatePerception);

    SightConfig->SightRadius = 2000.f;
    SightConfig->LoseSightRadius = 2000.f + 20.f;
    SightConfig->PeripheralVisionAngleDegrees = 90.0f;

    SightConfig->DetectionByAffiliation.bDetectEnemies = true;
    SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
    SightConfig->DetectionByAffiliation.bDetectNeutrals = true;

    PerceptionComponent->ConfigureSense(*SightConfig);
    PerceptionComponent->SetDominantSense(SightConfig->GetSenseImplementation());
}

void ABaseCharacter::UpdatePerception(TArray<AActor*>ActorsInSight)
{
    GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, TEXT("UPDATE PERCEPTION"));
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_32265baf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_32265baf](https://forums.unrealengine.com/u/anonymous_user_32265baf)\
**Post date:** [July 4, 2016, 9:16pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/2 "2016-07-04T21:16:12Z")

</div>

I have fixed the problem.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44ea4ec1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44ea4ec1](https://forums.unrealengine.com/u/anonymous_user_44ea4ec1)\
**Post date:** [August 19, 2016, 5:51pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/3 "2016-08-19T17:51:01Z")

</div>

Hi, could you please tell how did you fixed it? I am having exactly the same problem.

---

<div class="post-metadata">

**Author:** ![RyuMaster](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyuMaster](https://forums.unrealengine.com/u/RyuMaster)\
**Post date:** [September 3, 2016, 8:01am UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/4 "2016-09-03T08:01:17Z")

</div>

Its like because pivot point is below surface.

---

<div class="post-metadata">

**Author:** ![Vrtual](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vrtual/32/1025445_2.png) [@Vrtual](https://forums.unrealengine.com/u/Vrtual)\
**Post date:** [March 16, 2017, 11:18pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/5 "2017-03-16T23:18:58Z")

</div>

What did you do to fix this?

---

<div class="post-metadata">

**Author:** ![PollerBoom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PollerBoom](https://forums.unrealengine.com/u/PollerBoom)\
**Post date:** [August 17, 2017, 5:01pm UTC](https://forums.unrealengine.com/t/ai-perception-c-not-firing/362912/6 "2017-08-17T17:01:35Z")

</div>

U have first SetPerceptionComponent inside the AI Controller class, as there is a default PerceptionComponent within AI Controller. Then, use GetAIPerceptionComponent()-\>OnPerceptionUpdated.AddDynamic( paramaters ) instead of the AIPerceptionComponent that u constructed by urself. I stucked at this for hours, and finally figure that out by accident.

Hope this message is useful.  
Cheers.  
UE 4.16
