x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Pawn Sensing to Socket

Hello Guys,

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

Thanks in advance!

Product Version: Not Selected
Tags:
more ▼

asked Mar 20 '15 at 08:39 PM in Blueprint Scripting

avatar image

ganoncl
31 3 9 14

avatar image ganoncl Apr 06 '15 at 04:20 PM

Hello, there is some news about this?

avatar image unrealChris May 11 '15 at 06:48 AM

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

avatar image hellkama Oct 31 '15 at 05:40 AM

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

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

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. alt text alt text Or you can use without Tickrate: alt text

more ▼

answered Sep 08 '17 at 01:51 PM

avatar image

Dj EKI
36 14 10 16

(comments are locked)
10|2000 characters needed characters left

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);
     }
 }




more ▼

answered Jun 07 '18 at 08:47 PM

avatar image

puffneki
6 1 1

avatar image K6L2 Jun 16 '18 at 10:43 PM

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

avatar image haimat Jun 20 '18 at 12:45 PM

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?

avatar image puffneki Jun 20 '18 at 03:32 PM

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().

(comments are locked)
10|2000 characters needed characters left

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

more ▼

answered Mar 20 '17 at 07:50 AM

avatar image

BRS Office
1 1 4

avatar image Vaheva Nov 07 '17 at 02:53 AM

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.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question