Component

Introduction Components are a core part of any Component Based Development, they are Objects which define modular reusable behavior. In Unreal Engine 4 Actors are composed of components, every Acto...

Updated over 4 years ago Edit Page Revisions

Introduction

Components are a core part of any Component Based Development, they are Objects which define modular reusable behavior. In Unreal Engine 4 Actors are composed of components, every Actor has a base Scene Component which is referred to as the Root Component of that Actor and provides its world transform.

Component Types

Actor Component

  • UActorComponent is the base type for any Component which will extend behaviors of an Actor, including Scene Components.

Scene Component

  • USceneComponent has a transform allowing it to be physically present in the game world at a certain location. This also means that all components allowing attachment are either of USceneComponent type or inherit from it.

Primitive Components

  • These types of Components are subclasses of Scene Component and add some form of physical representation in the game world. Examples include UStaticMeshComponent, USkeletalMeshComponent, and UTextRenderComponent.

Physics Components

  • For more information on Physics Components, including Collision Components please see Physics. Examples include UCapsuleComponent.

Visualization Components

  • These types of Components are only visible in Editor Builds, they are not relevant for gameplay purposes.

Creating Components

We assume you are familiar with Creating Classes.

YourActor.h

UCLASS()
class AYourActor : public AActor
{
    GENERATED_BODY()

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class USpringArmComponent* CameraBoom;
};

We assume you are familiar with Creating Blueprints deriving from Actor.

Default Components

YourActor.cpp in the constructor of your Class.

AYourActor::AYourActor()
{
    CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom"));
}

File:BlueprintActorAddComponentButton425.png

File:BlueprintActorAddComponentList425.png

File:BlueprintActorAddComponentListSearch425.png

Runtime

Very similar to creating any other UObject at runtime except you have to make sure your Component is Registered.

    auto *InstanceMesh = NewObject (Master);
    InstanceMesh->CreationMethod = EComponentCreationMethod::Instance;
    InstanceMesh->SetMobility(EComponentMobility::Type::Stationary);
    InstanceMesh->AddInstance(FTransform(Rotation, Location, FVector(1.0f, 1.0f, 1.0f)));
    InstanceMesh->RegisterComponent();
    InstanceMesh->SetStaticMesh(Mesh);

On your graph if you Right Click and bring up the Blueprint Context Menu you type add and you will see a list of components in the menu to select from.

File:BlueprintActorAddComponentGraphSearch425.png

File:BlueprintActorAddComponentListSearchUp425.png

You can also do this from Blueprints Construction Script

Editor

You may want a Component which is only used in the Editor, this also gives you the ability to have an editor tickable component if you require it to update.

New Components Types

YourComponent.h

UCLASS(HideCategories = ("Rendering", "Input", "HLOD", "Sockets", "Collision"), meta = (BlueprintSpawnableComponent))
class UYourComponent : public UActorComponent
{
    GENERATED_BODY()
}

In the Content Browser press the big green Add New button or Right Click in the empty space on the tab. You will see a list of Objects you can create, go down to the Blueprint Category and select Blueprint Class.

You will see a floating window asking you to pick your Blueprints Parent Class (more info here), you can select either Actor or Scene Component from the quick button list or expand the search box and find Actor Component using the arrow to drop that down. Now you have a list of every Component available to you, it includes those found in Plugins.

Attaching Components

How to attach components, link to attaching actors

Detaching Components

Replicating Components

Editor Tick Components

== Further Reading ==

Components

Programming Guide to Components

Component Replication

Component Window in Unreal Editor

Blueprint API