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

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

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

Oh sorry.
Here you go

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.

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

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.

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

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.

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

Which version are you using?

I am using UE4 4.27

@Limanima @SunbeamOut I’ve sent the whole project below.
Download The Whole Project

1 Like

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.

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.

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

1 Like

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 :thinking:

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.

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.

1 Like

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

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

1 Like

Ok thanks I can understand :slight_smile: