# Pawn Sensing to Socket

**URL:** <https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913>\
**Category:** AI\
**Tags:** unreal-engine, question, Blueprint, CPP\
**Created:** [March 20, 2015, 8:39pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913 "2015-03-20T20:39:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d04ca74b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d04ca74b](https://forums.unrealengine.com/u/anonymous_user_d04ca74b)\
**Post date:** [March 20, 2015, 8:39pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/1 "2015-03-20T20:39:04Z")

</div>

Hello Guys,

Someone know how to attach the Pawn Sensing to socket or bone??? (c++ or blueprint)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d04ca74b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d04ca74b](https://forums.unrealengine.com/u/anonymous_user_d04ca74b)\
**Post date:** [April 6, 2015, 4:20pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/2 "2015-04-06T16:20:54Z")

</div>

Hello, there is some news about this?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c234d6f3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c234d6f3](https://forums.unrealengine.com/u/anonymous_user_c234d6f3)\
**Post date:** [May 11, 2015, 6:48am UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/3 "2015-05-11T06:48:55Z")

</div>

Yeah I think is a bug where you can’t set the socket, im in 4.7.6

---

<div class="post-metadata">

**Author:** ![hellkama](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hellkama](https://forums.unrealengine.com/u/hellkama)\
**Post date:** [October 31, 2015, 5:40am UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/4 "2015-10-31T05:40:47Z")

</div>

Has anyone been able to attach the pawn sensing component to a socket?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8474fbfb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8474fbfb](https://forums.unrealengine.com/u/anonymous_user_8474fbfb)\
**Post date:** [March 20, 2017, 7:50am UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/5 "2017-03-20T07:50:16Z")

</div>

my idea is to put the pawn sensing in a child actor , then attach the childe actor to te bone

---

<div class="post-metadata">

**Author:** ![Dj\_EKI](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dj\_EKI](https://forums.unrealengine.com/u/Dj_EKI)\
**Post date:** [September 8, 2017, 1:51pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/6 "2017-09-08T13:51:02Z")

</div>

This works only with an Character, or Pawn (AICharakter). Create a second Pawn Actor and rename it to “sensing”. Add a Component PawnSensing in “sensing”.  
In your Character, where PawnSensing should work, you must use SpawnAIFromClass and spawn your “sensing”. Then a tickrate must copy the location and rotation of the socket.

![212765-2017-09-08-15-45-48-fuchscharakter.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/0/9/709a63f979d57a96b751ebe7caf0bd310e9fdcbc.jpeg)

 ![212766-2017-09-08-15-46-25-fuchscharakter.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/4/694102ca6b51f59c37de2290007f2956b9d584f5.jpeg)

Or you can use without Tickrate:

 ![212767-2017-09-08-15-57-03-fuchscharakter.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/f/69ff9facdfce78ef6ba369be34d70e4fb03c0814.jpeg)

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [November 7, 2017, 2:53am UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/7 "2017-11-07T02:53:22Z")

</div>

This is crazy idea but semi working (tested). I think it can create bugs, because this is not rotating in all axes, only horizontally. My character rotating head around - left/right - up/down and as I see, I can’t use any ready engine solutions for this.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_db06b41e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_db06b41e](https://forums.unrealengine.com/u/anonymous_user_db06b41e)\
**Post date:** [June 7, 2018, 8:47pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/8 "2018-06-07T20:47:27Z")

</div>

As of version 4.19.2 you still can’t attach a UPawnSensingComponent to a socket, but you can achieve the same with the following setup:

1. If you don’t already have, create a subclass of APawn or ACharacter, whatever Actor should your sensor belong to.
2. Override the AActor::GetActorEyesViewPoint() method to your needs. It should basically populate input parameters with the head location and rotation of your character.
3. Create a subclass of UPawnSensingComponent.
4. Override the UPawnSensingComponent::GetSensorRotation() method to use the FRotator object from the overridden AActor::GetActorEyesViewPoint() method.

And that’s about it.

Overridden method in my UPawnSensingComponent subclass:

```
FRotator UExtendedPawnSensingComponent::GetSensorRotation() const {
	FRotator SensorRotation(FRotator::ZeroRotator);
	FVector SensorLocation;
	const AActor* SensorActor = GetSensorActor();

	if (SensorActor != NULL) {
		SensorActor->GetActorEyesViewPoint(SensorLocation, SensorRotation);
	}

	return SensorRotation;
}

```

Overridden method in my AActor subclass:

```
void AHumanCharacter::GetActorEyesViewPoint(FVector& OutLocation, FRotator& OutRotation) const {
	const USkeletalMeshSocket* HeadSocket = GetMesh()->GetSocketByName(FName("headSocket"));
	if (HeadSocket && AnimInstance) {
		const USkeletalMeshComponent* SkelMesh = AnimInstance->GetSkelMeshComponent();
		const FVector HeadLocation = HeadSocket->GetSocketLocation(SkelMesh);
		FRotator CharRotation = GetActorForwardVector().Rotation();
		const float BodyYaw = AnimInstance->GetRelativeUpperBodyRotation();
		const float Diff = CharRotation.Yaw - BodyYaw;
		const float Angle = FMath::Abs(Diff) > 180 
			? 360 - FMath::Abs(Diff) : Diff;
		
		CharRotation.Yaw = Angle;

		OutLocation = HeadLocation;
		OutRotation = CharRotation;
	}
	else {
		Super::GetActorEyesViewPoint(OutLocation, OutRotation);
	}
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_57741f591](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_57741f591](https://forums.unrealengine.com/u/anonymous_user_57741f591)\
**Post date:** [June 16, 2018, 10:43pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/9 "2018-06-16T22:43:22Z")

</div>

Excellent solution! Way better than the Blueprint hack w/ attaching a child Actor. Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [June 20, 2018, 12:45pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/10 "2018-06-20T12:45:35Z")

</div>

Thanks for this solution, it seems to be working fine. However, I am wondering, where does the AnimInstance object come from? I have added your code to our custom Character-derived class, but then AnimInstance is an invalid identifier. Any ideas?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_db06b41e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_db06b41e](https://forums.unrealengine.com/u/anonymous_user_db06b41e)\
**Post date:** [June 20, 2018, 3:32pm UTC](https://forums.unrealengine.com/t/pawn-sensing-to-socket/311913/11 "2018-06-20T15:32:36Z")

</div>

Hi haimat,  
That AnimInstance is a custom class derived from UAnimInstance which I defined in my controller. So, the GetRelativeUpperBodyRotation() method is not something you have in your default UAnimInstance class. It just returns the value of the rotation of the head and upper torso that are the member values of my custom anim class and are being hooked to a Bone transform node in the blueprint.  
Btw, you can get the default anim instance from your controller with GetMesh()-\>GetAnimInstance().
