How to attach ActorComponent to my Actor in C++

Hi,

So i created a custom component for my actor , manually through the asset folder.
Right Click → Create new C++ class → Show all class - > Actor Component.

Not sure how do you actually attach this component to the actor through c++ code. I did it manually through the editor, but i actually want it to be in my actor.

USphereComponent* SphereComponent = CreateDefaultSubobject(TEXT(“RootComponent”));

look for more details here
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/

I understand USphereComponent* is like an existing built component. but what about custom components?

MySomekindOfCustomComponent* myCompomemt = CreateDefaultSubobject(TEXT(“myComponent”));

Wait… so how does it know how to select the actor component i made in my asset?
And i tried that… it gave me this error
identifider “MySomekindOfCustomComponent” is undefined

When you made your c++ actor component ue wizard generated header (.h) file which define it class. Then it become available to other cpp classes you create.
Do not forget to include your component’s header file in the cpp where you want to use it.