O'Reilly logo

Unreal Engine 4 Scripting with C++ Cookbook by Stephen Whittle, William Sherif

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Attaching components to create a hierarchy

When creating custom Actors from components, it is important to consider the concept of Attaching. Attaching components together creates a relationship where transformations applied to the parent component will also affect the components that are attached to it.

How to do it...

  1. Create a new class based on Actor using the editor, and call it HierarchyActor.
  2. Add the following properties to your new class:
    UPROPERTY()
    USceneComponent* Root;
    UPROPERTY()
    USceneComponent* ChildSceneComponent;
    UPROPERTY()
    UStaticMeshComponent* BoxOne;
    UPROPERTY()
    UStaticMeshComponent* BoxTwo;
  3. Add the following code to the class constructor:
    Root = CreateDefaultSubobject<USceneComponent>("Root"); ChildSceneComponent = CreateDefaultSubobject<USceneComponent>("ChildSceneComponent"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required