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"

Attaching weapons to sockets

Hello, So I am currently trying to attach my weapon/actor to the player socket at the hand. I trace to see if the player is looking at the object, then if the player presses the "Use" button it i call the Use method, where I pass in a AUsableItem Parameter. When I call this I am attempting to attach the item inside the socket that I set up in the skeleton:

 void APlayerCharacter::Use(AUsableItem* curItem){
     FVector loc = FirstPersonMesh->GetSocketLocation(FName("RightItemSocket"));
     curItem->AttachRootComponentTo(FirstPersonMesh, FName(TEXT("RightItemSocket")), EAttachLocation::SnapToTarget);

This is the code I found, but it does not work. Wondering if someone else has something that might help me with this?


Product Version: UE 4.9
more ▼

asked Oct 05 '15 at 03:04 AM in C++ Programming

avatar image

122 26 22 29

avatar image joelComberiati Oct 05 '15 at 05:59 AM

Can anyone help me with this? I have been searching for an answer for a while

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

1 answer: sort voted first

You can attach Mesh components as follows:


 // Constructor
 USkeletalMeshComponent* PlayerMesh;
 FName PlayerWeaponSocketName = TEXT("YourSocketName");
 USkeletalMeshComponent* WeaponMesh;


     // Create PlayerMesh Mesh Component
     PlayerMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("PlayerMesh"));
     // Find and assign the mesh using constructor helpers
     static ConstructorHelpers::FObjectFinder<USkeletalMesh> PlayerMeshOb(TEXT("SkeletalMesh'/Path/To/Your/Mesh'"));
     if (PlayerMeshOb.Object) 
     // Set PlayerMesh as rootcomponent
     RootComponent = PlayerMesh;
     // Create Weapon Mesh Component
     WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
     // Find and assign the mesh using constructor helpers
     static ConstructorHelpers::FObjectFinder<USkeletalMesh> WeaponMeshOb(TEXT("SkeletalMesh'/Path/To/Your/Mesh'"));
     if (WeaponMeshOb.Object) 
     // Attach Weapon mesh to PlayerMesh
     WeaponMesh->AttachTo(PlayerMesh, PlayerWeaponSocketName);
     // Do other stuff
more ▼

answered Oct 05 '15 at 06:56 AM

avatar image

2.6k 95 41 111

avatar image joelComberiati Oct 06 '15 at 01:22 AM

After trying this, and doing:

 curItem->getItemMesh()->AttachTo(FirstPersonMesh, FName("RightItemSocket") );

Still does not work, no errors, but when I do GetAttachParentSocketName() it returns none

avatar image staticvoidlol Oct 06 '15 at 07:55 AM

Could you elaborate on what you mean by "Still does not work". Is the Weapon Mesh visible but not attached, or not visible at all?

avatar image joelComberiati Oct 06 '15 at 11:46 PM

Well, Like I said, no errors, but this is what happens in the editor: alt text The object just remains in place, does not move at all

avatar image joelComberiati Oct 07 '15 at 12:39 AM

I didnt take off physics, thats why it didnt work

avatar image joelComberiati Oct 06 '15 at 01:25 AM

Also is there a way to attach the whole Actor? like instead of just the mesh?

avatar image cahitburak Oct 06 '15 at 08:23 AM

If the Mesh is the Root Component of the UsableItem then attaching the Mesh to the socket means attaching the UsableItem to the socket. It is the same thing.

avatar image joelComberiati Oct 06 '15 at 11:06 PM

Thank you, that helps

(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