"Parent Socket" from c++ created object

Hi,

today I created a capsule component via the blueprint menu (add component) and I was able to set my skeletal mesh component as the parent for this new capsule. I was also able to get a dropdown menu when clicking on the option “Parent Socket” and chose to whatever socket/bone I want to attach this new capsule.
However after creating the same capsule with c++ I was not able to use the dropdown menu and it was plain empty.

Here is my code and a screenshot.

.h:

  /**Hitbox used to determine headshots */
    	UPROPERTY(VisibleDefaultsOnly, Category = Camera)
    		UCapsuleComponent* HitBox_Head;

.cpp:

	HitBox_Head = ObjectInitializer.CreateDefaultSubobject<UCapsuleComponent>(this, TEXT("HitBox_Head"));
	HitBox_Head->SetRelativeLocation(FVector(0.f,0.f,0.f));
	HitBox_Head->SetRelativeRotation(FRotator(0.f, 0.f, 0.f));
	HitBox_Head->SetCapsuleHalfHeight(20);
	HitBox_Head->SetCapsuleRadius(20);
	HitBox_Head->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
	HitBox_Head->SetCollisionResponseToChannel(COLLISION_WEAPON, ECollisionResponse::ECR_Block);
	HitBox_Head->AttachTo(GetMesh());

http://puu.sh/kxo1K/bd4ccfab04.png

Hey -

This is a known issue that is currently open in our tracking database (UE-20519). It is possible to attach the component to a socket by specifying the socket in code. Here is an example from Character.cpp: FP_Gun->AttachTo(Mesh1P, TEXT("GripPoint"), EAttachLocation::SnapToTargetIncludingScale, true);

Cheers

This is a really old question and I believe now you can just do this now (in case anyone else is wondering):

HitBox_Head->SetupAttachment(GetMesh(), "head");

Where "head" is the name of the socket you would have selected in the Parent Socket dropdown.

“However after creating the same
capsule with c++ I was not able to use
the dropdown menu and it was plain
empty.”

This is because you can not set or change the socket on inherited components (in your case the inherited component being the HitBox_Head). If you hover over the magnify glass next to Parent Socket it will tell you this. Hope this helps!

It doesn’t work, at least when called in actor constructor.
Object is attached to parent, but “Parent Socket” field is still null in editor and transform won’t be relative to passed socket :frowning:

HeadMesh = CreateDefaultSubobject(TEXT("HeadMesh"));
HeadMesh->SetupAttachment(BodyMesh, FName(TEXT("NeckSocket"))); // THIS DOESN'T WORK!

EDIT: errata corrige, it works! you only need to assign the skeletal mesh to the parent component in the c++ constructor and then attach the child component (this is obvious, but I didn’t get it at first)

1 Like

Could you share code of the fix?

USkeletalMesh* BodySkeletalMesh = UFunctionLibrary::GameData->PcBodySkeletalMesh; // in our project, game data is a static var to access game singleton where skeletal mesh asset is stored
BodyMesh->SetSkeletalMesh(BodySkeletalMesh);
HeadMesh->SetupAttachment(BodyMesh, FName(TEXT("NeckSocket")));

Did your fix fill in the null Parent Socket field for you? I used

CameraBoom->SetupAttachment(GetMesh(), FName(TEXT(“neck_01”)));

inside the character constructor, and it adds the neck_01 socket as a parent, performing as expected in level editor, but parent socket field still shows up as null on the blueprint