In most of the tutorials I have seen, an empty scene object is used as the Root Component of many actors. I am wondering how should I correctly be moving my actors if my other components are attached to the root, this is my current hierarchy:
if (!RootComponent)
{
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component"));
}
PaddleMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Paddle Static Mesh"));
PaddleMeshComponent->SetupAttachment(RootComponent);
I have a static mesh which is attached to an empty scene object. I am adding forces to this actor like so:
PaddleMeshComponent->AddImpulse(CurrentVelocity, NAME_None, true);
Is this correct?
The reason I ask is because I am currently trying to get a ball actor to follow a paddle actor before the ball is launched, but the ball remains in place and does not move with the following code:
if (!bIsLaunched)
{
BallMeshComponent->SetWorldLocation(Paddle->GetTargetLocation());
}
However, the ball will follow the paddle if I remove the empty scene component from the paddle and set the static mesh component as the root like so:
PaddleMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Paddle Static Mesh"));
RootComponent = PaddleMeshComponent;
I feel like something I’m doing wrong is incorrect, am I correctly setting Root Components? Do I have my movement logic wrong? Any insight would be appreciated.