Correct way to have custom SceneComponents that contain other SceneComponents

I’m not an expert just started learning few weeks ago, I do read engine code a lot every day to boost my knowledge, I might be wrong but your constructor seems to be bad.



 UGearBox::UGearBox(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
{  
  GearStick = CreateDefaultSubobject<USlideLever>(TEXT("GearStick"));
    GearStick->SetupAttachment(this);
     PrimaryComponentTick.bCanEverTick = false;
} 

This is user code obviously and it looks like it attaches a component to it self, but whether the UGearBox object is considered valid at this point is what I don’t know for sure so here is how it goes.
You said you don’t use actors so much but just components, you should think of Actors as containers of components therefore know that components on it’s own means nothing.
Every Actor class has a root component member which is by default is nullptr.
In order to start adding componets to your actor (that is component container) you should assign exaclty one component to RootComponent pointer. that one component should inherit from
USceneComponent or you could create dummy USceneComponent and attach it to your actor to become root:

for example:


ExampleActorConstructor()
{
          USceneComponent* MyRoot = CreateDefaultSubobject<USceneComponent>("MyRoot");
          this->RootComponent = MyRoot; // this-> not needed of course, but denote that RootComponent is member of Actor!

          // now start adding your components to MyRoot as you wish
          UStaticMeshComponent* mesh = CreateDefaultSubobject<UStaticMeshComponent>("MyMesh");
          mesh->SetupAttachment(MyRoot);
          // and so on...
}

Know that anything you place into a world is an Actor or inherits from an Actor, I think you can’t place component into the level, that sounds odd because as I said Actors are containers and components are Actor members, that is what actor consists of (that’s how all this actor/componets stuff seems to be designed)

Hope that helps to some extent.

EDIT:
I just now figured out this thread is 2years old rofl :smiley:
Never mind hopefully **PaRaNo0 **learns something here.