Attach a component to an inherited component c++

Hi, I’d like to know how to attach a component to an inherited component in c++.
If it is not an inherited base component you can just write: component2->SetupAttachment(component1);. But if it is an inherited component, for example the skeletal mesh component “Mesh” from the parent “character”, you can’t just write the name of the component. I think it’s because you don’t have direct access to the “Mesh” variable. What can I do?

Children have access to all public and protected parent properties. However, ACharacter’s Mesh is private

but you still can access it with GetMesh(), which is a public method

247909-getmesh.png

Thx for the quick reply. But how exactly do I implement this to the attachement? I tried it like this:MainCollision->SetupAttachment(GetMesh());. Because the value isn’t a USceneComponent, but a USkeletalMeshComponent, it doesn’t work.

Hello Aneos,
basically USkeletalMeshComponent ist a childclass of USceneComponent (UE4 API), so it should be of the correcht type for this function. What exactly is the given error-message when try to compile the above example?

Did you compile it or was it Intellisense that underlined the line as incorrect? I have it working no problem

248210-setupattachment.png

Ok sry, my mistake. I was confused, because GetMesh() was red underlined and nothing happended when I compiled. But after I deleted my line and rewrote it, it worked. Thanks!

Thx for the reply. I could solve it now.