# C++ component attachments and deriving to BP

**URL:** <https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373>\
**Category:** Character & Animation\
**Tags:** socket-reference, reference-blueprint, unreal-engine, CPP, question\
**Created:** [October 3, 2019, 3:30pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373 "2019-10-03T15:30:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Endersky1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Endersky1](https://forums.unrealengine.com/u/Endersky1)\
**Post date:** [October 3, 2019, 3:30pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/1 "2019-10-03T15:30:59Z")

</div>

I have started a project in which I’m determined to learn how to use C++ because I’m used to blueprints now and I prefer programming than BP so excuse me if this is a stupid question. I am working on a player character class in C++ and I want to change the camera spring arm attachment from the root to the head socket so I can make the character’s head rotation connected to the camera but I can’t figure out what combination of attachment type and reference I can use to get it to work. I currently just have this since I wasn’t able to get it to work:

```
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);

```

I also am trying to set up the animation BP to my blueprint I’m using that’s derived from this class but whenever I try to cast to the blueprint derived from the C++ class it immediately fails. I know it’s not an issue of my doing the blueprints wrong because I’m doing it just like in the documentation and I have my bp set to autoposses. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![GarnerP57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarnerP57](https://forums.unrealengine.com/u/GarnerP57)\
**Post date:** [October 5, 2019, 2:37pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/2 "2019-10-05T14:37:40Z")

</div>

Assuming the head socket is a socket you added to the SkeletalMesh and named it “HeadSocket” something like this should work on a character constructor.

```
	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Camera Boom"));
	SpringArm->SetupAttachment(GetMesh(), FName("HeadSocket"));
```

---

<div class="post-metadata">

**Author:** ![Endersky1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Endersky1](https://forums.unrealengine.com/u/Endersky1)\
**Post date:** [October 7, 2019, 2:55pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/3 "2019-10-07T14:55:53Z")

</div>

It tells me my GetMesh() is incompatible with the type USceneComponent because it’s of type USkeletalMeshComponent

---

<div class="post-metadata">

**Author:** ![GarnerP57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarnerP57](https://forums.unrealengine.com/u/GarnerP57)\
**Post date:** [October 7, 2019, 3:57pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/4 "2019-10-07T15:57:37Z")

</div>

It should compile regardless since a USkeletalMeshComponent IsA SceneComponent

---

<div class="post-metadata">

**Author:** ![ilbeyataberkcan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ilbeyataberkcan](https://forums.unrealengine.com/u/ilbeyataberkcan)\
**Post date:** [October 8, 2019, 10:25am UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/5 "2019-10-08T10:25:59Z")

</div>

Check **[THIS](https://answers.unrealengine.com/questions/355879/attach-object-to-skeletal-mesh-socket-c.html)** entry on answerhub. Seems like you have the same problem with him.

---

<div class="post-metadata">

**Author:** ![Endersky1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Endersky1](https://forums.unrealengine.com/u/Endersky1)\
**Post date:** [October 8, 2019, 2:43pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/6 "2019-10-08T14:43:44Z")

</div>

wow, that is really aggravating… So the moral of the story is never trust Intellisense I assume?

edit: If you can add this all as an answer I can set it as correct so future people see and you get the karma

---

<div class="post-metadata">

**Author:** ![GarnerP57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarnerP57](https://forums.unrealengine.com/u/GarnerP57)\
**Post date:** [October 8, 2019, 8:00pm UTC](https://forums.unrealengine.com/t/c-component-attachments-and-deriving-to-bp/456373/7 "2019-10-08T20:00:43Z")

</div>

Intellisense is a helping hand, it is the compiler (output log) that is your real friend. Intellisense often gives up if it has to do any deep searching.
