From UE4: Community Wiki
Jump to: navigation, search

This article is a preliminary version, it is subject to change.


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[edit]

Actor Component[edit]

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

Scene Component[edit]

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[edit]

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[edit]

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

Visualization Components[edit]

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

Creating Components[edit]

We assume you are familiar with Creating Classes.


class AYourActor : public AActor

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

Default Components[edit]

YourActor.cpp in the constructor of your Class.

	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));


Very similar to creating any other Object at runtime except you have to make sure you call Register Component.

	auto *InstanceMesh = NewObject <UInstancedStaticMeshComponent>(Master);
	InstanceMesh->CreationMethod = EComponentCreationMethod::Instance;
	InstanceMesh->AddInstance(FTransform(Rotation, Location, FVector(1.0f, 1.0f, 1.0f)));
UActorCompon ... 	AddComponent
    FName TemplateName,
    bool bManualAttachment,
    const FTransform & RelativeTransfor...,
    const UObject * ComponentTempla...
    UActorComponent * Template,
    const FName InName


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. YourActor.h

    /** Camera boom positioning the camera behind the character */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Camera", meta=(AllowPrivateAccess = "true"))
    USpringArmComponent* CameraBoom;
    FORCEINLINE USpringArmComponent* GetCameraBoom() const { return CameraBoom; }

In the Constructor of YourActor.CPP

    // Create a camera boom (pulls in towards the player if there is a collision)
    CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
    CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
    CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

New Components Types[edit]


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

Attaching Components[edit]

Most of the base functionality for working with Components is defined in the Actor Class as we work with Components a majority of the time from the Actor scope.

Detaching Components[edit]

Finding Components[edit]


Replicating Components[edit]

Physics Components[edit]

Ticking Components[edit]

In-Editor Ticking[edit]

This is just a matter of setting the correct variable that is defined in Actor Component.

	/** Should this component be ticked in the editor */
	uint8 bTickInEditor:1;

Further Reading[edit]