# "Parent Socket" from c++ created object

**URL:** <https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187>\
**Category:** C++\
**Tags:** socket, attach, unreal-engine, CPP, question\
**Created:** [October 3, 2015, 9:08pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187 "2015-10-03T21:08:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theololz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Theololz](https://forums.unrealengine.com/u/Theololz)\
**Post date:** [October 3, 2015, 9:08pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/1 "2015-10-03T21:08:18Z")

</div>

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](http://puu.sh/kxo1K/bd4ccfab04.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [October 5, 2015, 1:44pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/2 "2015-10-05T13:44:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Blindopoly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Blindopoly](https://forums.unrealengine.com/u/Blindopoly)\
**Post date:** [March 24, 2019, 9:18pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/3 "2019-03-24T21:18:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Curs0](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/curs0/32/470295_2.png) [@Curs0](https://forums.unrealengine.com/u/Curs0)\
**Post date:** [July 27, 2019, 4:43pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/4 "2019-07-27T16:43:16Z")

</div>

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 ☹

```
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)

---

<div class="post-metadata">

**Author:** ![AltairGamesLLC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AltairGamesLLC](https://forums.unrealengine.com/u/AltairGamesLLC)\
**Post date:** [February 11, 2024, 9:49pm UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/5 "2024-02-11T21:49:48Z")

</div>

Could you share code of the fix?

---

<div class="post-metadata">

**Author:** ![Curs0](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/curs0/32/470295_2.png) [@Curs0](https://forums.unrealengine.com/u/Curs0)\
**Post date:** [February 12, 2024, 11:38am UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/6 "2024-02-12T11:38:15Z")

</div>

```auto
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")));

```

---

<div class="post-metadata">

**Author:** ![Lizardrunner77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lizardrunner77](https://forums.unrealengine.com/u/Lizardrunner77)\
**Post date:** [February 24, 2024, 3:39am UTC](https://forums.unrealengine.com/t/parent-socket-from-c-created-object/334187/7 "2024-02-24T03:39:40Z")

</div>

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
