# \[UE4, C++\] AI Sight Perception problem - Enemy won't detect player and is trying to go outside the map!

**URL:** <https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809>\
**Category:** AI\
**Tags:** unreal-engine, UE4-27, question\
**Created:** [December 17, 2021, 8:14am UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809 "2021-12-17T08:14:26Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 2:39pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/23 "2021-12-21T14:39:53Z")

</div>

@Limanima @SunbeamOut Sorry for the ping, just wanted to know whether you guys found any solution to my question

---

<div class="post-metadata">

**Author:** ![SunbeamOut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SunbeamOut](https://forums.unrealengine.com/u/SunbeamOut)\
**Post date:** [December 21, 2021, 3:12pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/24 "2021-12-21T15:12:39Z")

</div>

Your link doesn’t work cause you didn’t make it accessible to anyone with the link.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/2/02034710f10a65ac85cefa9abbd45a35c2c5759a.png)

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 3:21pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/25 "2021-12-21T15:21:33Z")

</div>

Oh sorry.  
Here you go

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 21, 2021, 4:28pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/26 "2021-12-21T16:28:57Z")

</div>

Although I’m an experienced c++ developer I don’t have enough UE experience to help you out only by looking at the c++ code.  
I would probably need the complete UE project so I could test and debug, in order to check was is going on.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 4:45pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/27 "2021-12-21T16:45:29Z")

</div>

The complete UE4 project is about 2.15 gb, I’ll try sending it in a .zip file in drive with a link.

---

<div class="post-metadata">

**Author:** ![SunbeamOut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SunbeamOut](https://forums.unrealengine.com/u/SunbeamOut)\
**Post date:** [December 21, 2021, 5:20pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/28 "2021-12-21T17:20:53Z")

</div>

You don’t need to provide the whole folder. Most of the files are generated by the engine.  
You can delete .vs, Binaries, Build, DerivedDataCache, Intermediate, Saved folders, and nothing will be broken. The engine will just regenerate these files and that might take some time.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 5:23pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/29 "2021-12-21T17:23:05Z")

</div>

Okay but @Limanima wants it, I’ve sent you all the .cpp and .h files and .Target and etc.

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 21, 2021, 5:25pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/30 "2021-12-21T17:25:48Z")

</div>

No SunBeam is right. There are a lot of generated files you can delete.  
Make a copy and delete all that isn’t necessary from the copy.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 5:27pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/31 "2021-12-21T17:27:13Z")

</div>

I’ve already put it all in a .zip file 😀

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 21, 2021, 5:27pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/32 "2021-12-21T17:27:38Z")

</div>

Which version are you using?

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 5:28pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/33 "2021-12-21T17:28:19Z")

</div>

I am using UE4 4.27

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 21, 2021, 6:35pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/34 "2021-12-21T18:35:51Z")

</div>

@Limanima @SunbeamOut I’ve sent the whole project below.  
[Download The Whole Project](https://drive.google.com/file/d/126LLd0pBl1GrE8subtMP3Z2BMVTG2jJg/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 21, 2021, 8:53pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/35 "2021-12-21T20:53:21Z")

</div>

I’ve download the file but I have to install 4.27. It’s downloading…  
I tried to open it in 5.0 but it didn’t work.

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 21, 2021, 10:25pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/36 "2021-12-21T22:25:50Z")

</div>

Alright I have this up and running.  
I’ve never used the AI Perception component, but first thing I suspected as soon as executed your game is that the enemies seem to be sensing each other and they should only sense the player and that’s what’s happening. That’s why you get that random behavior from the enemies.  
In the AI Perception Component there are 3 checkboxes under AI Perception-\>Sensing config-\>Detect by Affiliation. Both enemies and the player are seen as “Neutrals”. Uncheck this and you will notice that the enemies stop moving.

Next thing I did , was duplicate your map and delete all enemies but one. Then I moved towards the enemy but nothing happened. The enemy won’t move. Then I activated debug tools for AI (check this link [AI Debugging | Unreal Engine Documentation](https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/ArtificialIntelligence/AIDebugging/).

I activated the AI Perception debug (numpad 4 after pressing ’ (apostrophe)) . This shows the AI perception radius and I noticed it is facing backwards the enemy. I then moved the player to the back of the AI enemy and he started moving.

This is happening because you have the mesh pointing in the wrong direction. Open the BP\_Enemy-\>Viewport. Notice the blue arrow? That’s the direction your character should be facing.  
Now, if you change this, the enemy will move backwards, but the sensing will be correct. You will have to fix this.

So first things you have to investigate:

1. Why are the enemies sensing enemies and not only the player?
2. Rotate your mesh 180 degrees in the BP\_Enemy and fix the backwards movement

PS: Let me know if you need more help

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 22, 2021, 3:02am UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/38 "2021-12-22T03:02:11Z")

</div>

I changed the mesh to -90 degrees from 90 degrees, now the character which is the enemy is facing towards the arrow, but still the sensing is incorrect. Am I doing something wrong 🤔

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 22, 2021, 5:23am UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/39 "2021-12-22T05:23:55Z")

</div>

I even changed all the enemies rotation in the details panel to 180 degrees so that they face the player, but still it won’t detect my player, I changed the movement speed from -375.0f, to 375.0f so that they run properly facing straight not backwards movement.

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 22, 2021, 9:50am UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/40 "2021-12-22T09:50:08Z")

</div>

Have you activated the AI perception debug?

I made the same changes as you (changed the mesh to face forwards, changed the movement speed to 375) and it is working just fine.  
The enemy is chasing the player correctly.  
Note that this only works with one enemy. If you have more enemies it will not work because enemies are chasing enemies.

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 22, 2021, 12:30pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/41 "2021-12-22T12:30:35Z")

</div>

So what should I do if I want 60 enemies to chase one player?

---

<div class="post-metadata">

**Author:** ![Limanima](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/limanima/32/248560_2.png) [@Limanima](https://forums.unrealengine.com/u/Limanima)\
**Post date:** [December 22, 2021, 1:38pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/42 "2021-12-22T13:38:06Z")

</div>

You have to find out why the AI Perception component is detecting the enemies. Investigate a little bit about that. I can’t do all the work for you ;).

PS: They are all chasing the player, that’s not the problem. The problem is that they are also chasing each other.

Edit:  
Here’s the solution for that problem. Haven’t tested it myself.

[UE4 - Team Sight AI Perception Enemy Detection Affiliation C++ - YouTube](https://www.youtube.com/watch?v=FEqnRxu5sFs)

---

<div class="post-metadata">

**Author:** ![DeadFalconking](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deadfalconking/32/250507_2.png) [@DeadFalconking](https://forums.unrealengine.com/u/DeadFalconking)\
**Post date:** [December 22, 2021, 3:17pm UTC](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809/43 "2021-12-22T15:17:24Z")

</div>

Ok thanks I can understand 🙂

[Previous page](https://forums.unrealengine.com/t/ue4-c-ai-sight-perception-problem-enemy-wont-detect-player-and-is-trying-to-go-outside-the-map/266809.md?page=1)
