Child components not following root component?

Hi all, I’m new to c++ and ue4 so forgive me if there is a very simple answer to this.
I’ve added a paper flipbook component and attached it to my box component root but when I go in the editor and drag in the blueprint, the flipbook component doesn’t follow the box collisions location and just stays at 0, 0, 0.

Here’s my code in my constructor:
AEnemyPawn::AEnemyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT(“BoxCollisionComponent”));
SetRootComponent(BoxCollision);

FlipbookComponent = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT(“FlipbookComponent”));
FlipbookComponent->AttachTo(RootComponent);

CurrentVelocity.X = -90.0f;
}

Any help is much appreciated, thank you :slight_smile:

If it’s in the constructor of AEnemyPawn, you can use FlipbookComponent->SetupAttachment(RootComponent) instead of AttachTo(…)
Also, I believe AttachTo() is deprecated and you might want to try AttachToComponent() instead. Eitherway, I think SetupAttachment will work in your example.

Thank you for your help, I just tried using FlipbookComponent->SetupAttachment(RootComponent); and AttachToComponent() but sadly there is no change in the editor, my flipbookcomponent still appears at a further away location than my box component when spawned in.

I’ve found the solution now, so if anyone else has this problem I put:
FlipbookComponent->SetupAttachment(GetRootComponent()); instead.
Thank you so much anyways for the help :slight_smile: