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 about 5 years ago

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 base Scene Component which is referred to as the Root Component of that Actor.

Component Types

Actor Component

This is the base type for any Component which will extend behaviors of an Actor.

UActorComponent - Official C++ Class Documentation

Scene Component

Have a transform and some form of physical representation in the game world.

UScenesComponent - Official C++ Class Documentation

Physics Components

For more information on Physics Components please see .

C++

Creating Components

We assume you are familiar with Creating Classes and/or Blueprints deriving from Actor.

Link that info!

AYourActor.h

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

Default Components

AYourActor.cpp in the constructor of your Class.

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

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);

New Components Types

AYourComponent.h

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

Blueprint

Creating Components

We assume you are familiar with Creating Classes and/or Blueprints deriving from Actor.

Link that info!

Default Components

There is a big green Add Components button in the Components window of the Blueprint Editor.

Runtime

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.

You can also do this from Blueprints Construction Script

New Components Types

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.

Pictures when thumbnails are working properly

Further Reading