# 4.8.1: AI Perception By Affiliation?

**URL:** <https://forums.unrealengine.com/t/4-8-1-ai-perception-by-affiliation/323528>\
**Category:** AI\
**Tags:** Perception, ai-controller, unreal-engine, question\
**Created:** [June 30, 2015, 7:59am UTC](https://forums.unrealengine.com/t/4-8-1-ai-perception-by-affiliation/323528 "2015-06-30T07:59:46Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![anonymous\_user\_640bfbb4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_640bfbb4](https://forums.unrealengine.com/u/anonymous_user_640bfbb4)\
**Post date:** [February 26, 2019, 10:15am UTC](https://forums.unrealengine.com/t/4-8-1-ai-perception-by-affiliation/323528/21 "2019-02-26T10:15:03Z")

</div>

Hello everyone!  
I have this exact same bug in 4.21.2 and, recently, Epic told me that this is not a priority, so I looked for a workaround. There are 3 options:

1. **Copy/Paste** : you can copy/paste values in the invisible field. Simply copy this line with whatever flag values you want and paste it over the bugged field in the details panel `(bDetectEnemies=True,bDetectNeutrals=True,bDetectFriendlies=True)`

2. **Grab the component** : add the component in Editor to your AI/Player Controller and then, in **BeginPlay()** within your actor c++ class, use `UAIPerceptionComponent* MyPerceptionComponent = FindComponentByClass<UAIPerceptionComponent>();`

3. **Force flags in c++** :

Now, in your AIController class (I’m assuming you’re using a child class of **AIController.h** ), add this line in the constructor:

```
//defined in parent class already, but never used. If you define your own, the Gameplay Debugger 
	//stops working
	//https://udn.unrealengine.com/questions/485016/view.html
	PerceptionComponent = CreateDefaultSubobject<UMyAIPerceptionComponent>("EnemyPerceptionComponent");	

```

Once the component you’re creating registers, it will trigger the previous code and it will override the flags for you.

See that comment? well, that’s a different problem I found in 4.21.2. Follow the link to understand see a complete explanation but, just so you know, AIController.h is already declaring **PerceptionComponent** and, if you add a perception component using your own variable (in your child class), you will run intro trouble.

Problems/Advantages of each solution:

1. Solution 1: easy to implement, but everybody needs to remember to copy paste that string and have it around.
2. Solution 2: Easy enough, but there’s a problem: if you use a variable (UPROPERTY) called **PerceptionComponent** in your base class, you will run into trouble because there’s a variable already called like that in **AIController.h**. I haven’t confirmed if, when you add an **AIPerceptionComponent** in Editor, is that the variable used by the Engine or if that variable stays as nullptr.
3. Solution 3: implementation is not as fast as the other ones but you can create exposed variables to tweak the flags per AIController. Also, is automated, once you write the code, doesn’t matter how many senses your designer add in editor, they will just work. Notice that only Sight and Hearing are being checked. That’s because they are the only senses that uses the Affiliation flags in the Engine. If you add your custom senses and they use Affiliation flags too, you will have to add them to that loop. That’s the one I’m using right now. So far, so good.

I opened this thread whit other bugs I found in the perception system.  
[AI PErception Component Bug](https://udn.unrealengine.com/questions/485016/view.html)

Cheers!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_49ae318c1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_49ae318c1](https://forums.unrealengine.com/u/anonymous_user_49ae318c1)\
**Post date:** [November 13, 2019, 9:52am UTC](https://forums.unrealengine.com/t/4-8-1-ai-perception-by-affiliation/323528/22 "2019-11-13T09:52:25Z")

</div>

The bug is still present in 4.23.1

[Previous page](https://forums.unrealengine.com/t/4-8-1-ai-perception-by-affiliation/323528.md?page=1)
