In this lesson, you will learn how to create parent-child relationships between components to make objects move, rotate, and scale in unison using SceneComponents.
The Power of Hierarchy
In Unreal Engine, an Actor is a container, but it doesn’t have a position of its own. Instead, it relies on its components to define its spatial presence. A SceneComponent is a special type of component that has a Transform (Location, Rotation, and Scale).
When you attach one SceneComponent to another, you create a parent-child hierarchy. The child component inherits the transformation of its parent. If you move the parent, the child moves with it automatically. This is essential for building complex objects, such as a sword attached to a character's hand, or a door attached to a frame.
Setting Up a Hierarchy
In C++, you define these relationships within the Actor constructor. We typically use a "Root" component to serve as the anchor for the entire Actor.
// In your Actor constructor
// 1. Create the parent
MyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = MyRoot;
// 2. Create the child
MyChild = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChildMesh"));
// 3. Attach the child to the parent
MyChild->SetupAttachment(RootComponent);
Why Transform Propagation Matters
Because the child is attached to the parent, its transform is calculated relative to the parent’s origin, not the world’s origin. This is known as Relative Transform.
If your parent SceneComponent is at world coordinate (100, 0, 0) and your child is at relative coordinate (50, 0, 0), the child will appear at world coordinate (150, 0, 0). If you rotate the parent, the child will orbit around the parent’s pivot point. This propagation makes managing complex objects intuitive, as you only need to update the parent’s transform to move the entire assembly through the game world.
Key Takeaway: SceneComponents provide the spatial "glue" for your Actors; by establishing a parent-child hierarchy, you enable child components to inherit transforms, allowing you to build complex, moving, and cohesive objects easily.