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"

Set Socket Location/Transform?

Hi,

I can't find the way how to set a socket location or transform. We have GetSocketLocation. So how to Set? And how to set socket rotation?

EDIT:

The socket of my enemy's hand should follow the spine bone/socket of my character.

 USkeletalMeshSocket const * EnemyhandR = Enemy1->GetMesh()->GetSocketByName("hand_r");
 USkeletalMeshSocket const * MHSpine3 = Enemy1->GetMesh()->GetSocketByName("spine_03");
 
 FVector EnemySLoc = Enemy1->GetMesh()->GetSocketLocation("hand_r");
 FVector MHSLoc = MH->GetMesh()->GetSocketLocation("spine_03");
 FVector Forward = (MHSLoc - EnemySLoc);
 FRotator SocketRot = FRotationMatrix::MakeFromX(Forward).Rotator();

And

 EnemyhandR->SetSocketRotation(SocketRot);

But no SetSocketRotation.

Product Version: UE 4.19
Tags:
more ▼

asked Mar 19 '18 at 12:09 PM in C++ Programming

avatar image

Tomza
70 3 7 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hey,

try to use:

 EnemyhandR->RelativeLocation = FVector(); 
 EnemyhandR->RelativeRotation = FRotator(); 
 EnemyhandR->RelativeScale = FVector(); 

but GetSocketByName() return const value, so you cannot modify EnemyhandR (it is read only).

You may try one of this (I'm not sure if it will work the way you want):

[1] cast GetSocetByName() to non-const

 USkeletalMeshSocket * EnemyhandR = const_cast<USkeletalMeshSocket*>(Cast<USkeletalMeshSocket>(Mesh->GetSocketByName("hand")));

[2] create a handler to USkeletalMesh

 USkeletalMesh * SkeletalMeshHandle;

next

 static ConstructorHelpers::FObjectFinder<USkeletalMesh> Finder_SkeletalMesh(TEXT("MySkeletalMesh"));
 Mesh->SetSkeletalMesh(Finder_SkeletalMesh.Object);
 SkeletalMeshHandle = Finder_SkeletalMesh.Object;

or override Mesh->SetSkeletalMesh().

Now you can find Socket

 USkeletalMeshSocket * EnemyhandR = SkeletalMeshHandle->FindSocket("hand");

[3] Instead of moving the Socket, you can move the object that is attached to it.

more ▼

answered Mar 19 '18 at 02:06 PM

avatar image

Shaggy41
341 2 7 5

avatar image Tomza Mar 19 '18 at 02:38 PM

Thank you, Shaggy41! Is there no way to make it simpler? So it is impossible to move socket. Maybe I can rotate a gun attached to the socket. But would be great to use the socket near the gun barrel to make it pointing at the player. It is an idea. I need to think about that.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

This is the code I got:

 USkeletalMeshSocket const* MHSpine3Const = MH->GetMesh()->GetSocketByName("GunSocket");
         USkeletalMeshSocket const* EnemySpine3Const = Enemy1->GetMesh()->GetSocketByName("GunSocket");
         if(MHSpine3Const && EnemySpine3Const){
             
             USkeletalMeshSocket* MHSpine3 = const_cast<USkeletalMeshSocket*>(MHSpine3Const);
             USkeletalMeshSocket* EnemySpine3 = const_cast<USkeletalMeshSocket*>(EnemySpine3Const);
             
             if (MHSpine3 && EnemySpine3) {
                 FVector MHSLoc = MHSpine3->GetSocketLocation(MH->GetMesh());
                 FVector Enemy1SLoc = EnemySpine3->GetSocketLocation(Enemy1->GetMesh());
                 FVector Forward = (MHSLoc - Enemy1SLoc);
                 FRotator PlayerRot = FRotationMatrix::MakeFromX(Forward).Rotator();
 
                 EnemySpine3->RelativeRotation = PlayerRot;
             }
         }

It works with sockets (sockets rotate), but now I know that I need to do the same not with sockets (it makes no sense), but with bones like spine_03 in the armature. How to get a specific bone in the armature? I need to rotate the bone of the enemy's armature (AI bot) to follow my player character.

more ▼

answered Mar 20 '18 at 09:13 AM

avatar image

Tomza
70 3 7 9

avatar image Tomza Mar 20 '18 at 10:29 AM

Why cannot I get a specific bone by:

 USkeletalMeshSocket const* EnemySpine3Const = Enemy1->GetMesh()->GetSocketByName("spine_03");


Is that for sockets only?

avatar image Tomza Mar 21 '18 at 08:11 AM

Nobody knows?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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