C++ Components stay at level origin

Hi Everyone,

every component that i created in cpp that is not the root component is created at the level position 0,0,0 (but relative position in details panel) when placed in the editor, but shows properly in the BP. For example i set up a Character class and added a CapsuleComponent as a collider with overlap events and then set it to visible in game to check what was going on. In Wireframe i then saw it at the level origin without it moving when the Character did.
So far i checked if the components are moveable and tried to set their relative position through the BP Constructor - sadly without success.

Can you show us how you’re creating and setting that capsule for example?

Does this happen only with this actor? If not, have you tried, recreating the actor?

Sure thing! its pretty basic and the compilation succeded without errors:

.h

    public:
    	// Sets default values for this character's properties
    	AFPSCharacter();
    
    	UPROPERTY(EditAnywhere, Category = "Capsule Overlap", BlueprintReadWrite)
    	UCapsuleComponent* CapsuleCollision;

and in the .cpp

    AFPSCharacter::AFPSCharacter()
    {
    	PrimaryActorTick.bCanEverTick = true;
    
    	CapsuleCollision = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collision"));
    	CapsuleCollision->InitCapsuleSize(30.0f, 50.0f);

and included respectivly CapsuleComponent.h or StaticMeshComponent.h

Its the same with every component on every actor that is created in c++. I also placed an actor with which the character should interact and i had to manually reset the position values in the details panel. And i re-implemented the components a few times

You need to call Component->SetupAttachment(GetRootComponent()) after your component is created to attach it.

yep that did the trick. On the Character it worked instantly but for some reason i had to recreate the actor Blueprints.
anyways - thanks!