AI Sight Perception to Custom Points

AI Sight Perception to Custom Points

In this post, Unreal Engine Developer course student Carlos shares his awesome detective work (and code) on getting AI sight perception to custom points…

On the way to creating a metal gear solid clone game, I was following the testing grounds videos. I already had guards with Sight sense to detect me.

At a certain point I put some barriers, what should then happen is that NPC shouldn’t see me standing up. But what I got was that the NPC was detecting me, which is wrong. I thought maybe the AI Sight perception only sees the actor location (only one point).

I started to search for the answer, I asked on and the Unreal engine forum. Someone suggested I add a sphere collision to the head, add this sphere into a collision channel. It didn’t work, so I continued searching. I googled “Unreal engine 4 head perception” and found this link in this page someone said that I should implement IAISightTargetInterface and override the CanBeSeenFrom method.

So, i tried:

First include and implements IAISightTargetInterface in the .h file of the character class:

Then on the public part of my class add the definition of the method:

And then finally the implementation of the method in the .cpp file:

I then had some link errors on the compiling process, so I went onto the gamedev discord server and PocketNerd and PartlyAtomic helped me a lot (thank you so much guys!). The solution was adding “AIModule” on the dependency modules string array on the build.cs file.

Once the code was compiled I tested the behaviour of the code and what I got was the true log when I was inside the AI Sight range and he can see the the character’s location point, and false also inside the range but with the visibility blocked. Out the Sight range the method wasn’t called.

The only thing that I needed to do then was to get all the sockets name, and iterate trough the sockets array to check if the AI was able to percept some of them, and that’s the code of the method:

And now it works perfectly 🙂



  1. Hi, great work.

    Did you make the viewing angle work in the direction of the head?


    • Hi Raziel, no, unreal does this for us 🙂 also for your info, when you do the sight perception for the NPC there is a field that is the angle view of that character.

  2. Thanks for that! It works! I have hard time trying to figure out more advanced stuff with AIPerception. Do You know anything about attaching it to pawn head socket/bone?

  3. I meant AIPerception component. It is by default attached to pawn/character center.

  4. Oh, hm… don’t really know but maybe moving the vector arrow? (the blue, i don’t know the exactly name right now)

  5. Michael Slivinski says:

    Awesome work. This is great. Was able to add this to my project in less than a minute. This coupled with moving the “sight” source location is a huge improvement.

  6. Carlos Pardo Vimes says:

    Hi Michael thanks for the comment 🙂 I’m glad to help someone 😀

Leave a Reply

Your e-mail address will not be published. Required fields are marked *