# AI Perception attachment

**URL:** <https://forums.unrealengine.com/t/ai-perception-attachment/413765>\
**Category:** AI\
**Tags:** socket, bone, Perception, attach, unreal-engine, question\
**Created:** [January 4, 2018, 9:21pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765 "2018-01-04T21:21:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_010570ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_010570ad](https://forums.unrealengine.com/u/anonymous_user_010570ad)\
**Post date:** [January 4, 2018, 9:21pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/1 "2018-01-04T21:21:41Z")

</div>

Hello,  
I want to attach AI Perception Component to characters head instead of capsule center. Does anyone know how to do it? I red somewhere that it can be done by making AIPerceptionComponent based class in C++ and adding functionality to GetLocationAndDirection function, but that was all. I’m not hardcore programmer and I guess that since AIPerception is in AIController, not in Character, that’s tricky to do.

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 4, 2018, 11:10pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/2 "2018-01-04T23:10:20Z")

</div>

Hi,

Maybe these two answers ([link1](https://answers.unrealengine.com/questions/229043/ai-perception-only-can-detect-middle-of-player.html?childToView=233111#answer-233111), [link2](https://answers.unrealengine.com/questions/421735/ai-perception-height.html?childToView=421779#answer-421779)) can help you achieve what you want 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_010570ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_010570ad](https://forums.unrealengine.com/u/anonymous_user_010570ad)\
**Post date:** [January 5, 2018, 8:31am UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/3 "2018-01-05T08:31:52Z")

</div>

Hey, thanks but it’s not what I want. I don’t want custom points on sensed character (well, I want, but I have that already). What I want is when my AI turns head, its vision cone rotates with it. Now its rotating only with whole character.

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 6, 2018, 10:14am UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/4 "2018-01-06T10:14:08Z")

</div>

Oh sorry, I misunderstood your question. Unfortunately, afaik this cannot be done in blueprints. The comment section doesn’t like Code blocks so I’m posting an updated answer with some steps on how to do it in C++.

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 6, 2018, 10:40am UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/5 "2018-01-06T10:40:26Z")

</div>

As was pointed out in [this](https://answers.unrealengine.com/questions/428340/pawnsense-ai-perception-orientation.html) archived post, **AIPerception** uses **GetActorViewPoint** to determine the **Sight Sense** location and orientation. Unfortunately, this function cannot be overridden in blueprints yet. However, you can very easily override it in C++ and update the actor viewport with the location and rotation of “head” bone to achieve the effect you want. Hence, if you really need this, you have to do a little bit of coding. It’s not that difficult though. Here’s a quick step by step guide on how to accomplish this:

1. In the **Content Browser** , click on the green button _Add New \> New C++ Class_. Select **Character** and name it **BaseCharacter**.

2. Th Engine will take a short moment to create this class and recompile the solution. If you’re on Windows and have Visual Studio installed, it will open automatically. Once the Visual Studio opens, go to the **BaseCharacter.h** and override **GetActorViewpoint** method as a **public** function by adding the following line within those curly brackets:

3. Go to **BaseCharacter.cpp** and add these few lines:

That’s it! Now go back to the Editor, and compile your solution. If you’re already in the blueprint version of **ThirdPersonTemplate** , then simply open the **ThirdPersonCharacter** blueprint, go to the **Class Settings** and on the top right, change the **Parent Class** to this **BaseCharacter**. If you’re building your own **Character** , then use this **BaseCharacter** as the parent and create a new blueprint from it (one simple way to do this is to find this C++ BaseCharacter class in the Content Browser, right-click on it and create a new blueprint class from it). Next, create an AIController, add the **AIPerception** to it, and enable **Sight Sense**. The **Yaw** angle of Sight Sense will automatically get updated as this Character turns his head.

Hope this helps.

~Vizgin

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_010570ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_010570ad](https://forums.unrealengine.com/u/anonymous_user_010570ad)\
**Post date:** [January 6, 2018, 1:02pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/6 "2018-01-06T13:02:20Z")

</div>

Now it works as it should 🙂 However I had to change RTS\_ParentBoneSpace to RTS\_World and Rotator() to Yaw, because it was keeping world rotation 0,0,0 when characters head was in default position, so vision cone wasn’t rotating even with the whole character.

I thought it we’ll be something more complicated 🙂  
Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Vizgin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vizgin](https://forums.unrealengine.com/u/Vizgin)\
**Post date:** [January 6, 2018, 1:17pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/7 "2018-01-06T13:17:51Z")

</div>

You’re welcome 🙂

Yes, you’re right. I missed the part that the bone coordinate system doesn’t get affected by the root motion. I’ll update the code soon.

---

<div class="post-metadata">

**Author:** ![MrGoatsy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mrgoatsy/32/918697_2.png) [@MrGoatsy](https://forums.unrealengine.com/u/MrGoatsy)\
**Post date:** [June 28, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/8 "2024-06-28T16:17:18Z")

</div>

Use this code instead as yours uses the wrong quotation marks due to the Epic forum migration:

```auto
void ABaseCharacter::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
{
    Location = GetMesh()->GetSocketLocation("head");

    Rotation = GetActorRotation();
    Rotation.Yaw -= GetMesh()->GetSocketTransform("head", RTS_ParentBoneSpace).Rotator().Roll;
}

```

---

<div class="post-metadata">

**Author:** ![Coyotekins\_YouTB1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Coyotekins\_YouTB1](https://forums.unrealengine.com/u/Coyotekins_YouTB1)\
**Post date:** [February 8, 2025, 6:46pm UTC](https://forums.unrealengine.com/t/ai-perception-attachment/413765/9 "2025-02-08T18:46:41Z")

</div>

THANK YOU!
