Skip to main content

Components

Components are sub-objects attached to your actor (a static mesh, a camera, a capsule, etc.). TPScript has high-level shortcuts and low-level control.

High-level: component name: type​

class my_turret extends actor meta: api=MYGAME_API
{
component body: capsule
component gun: static_mesh
component look: camera
}

component <name>: <type> is equivalent to:

  • a UPROPERTY(VisibleAnywhere, BlueprintReadOnly),
  • a member,
  • a CreateDefaultSubobject() call in the constructor.

High-level component keyword table​

KeywordUE class
static_meshUStaticMeshComponent
skeletal_meshUSkeletalMeshComponent
arrowUArrowComponent
cameraUCameraComponent
spring_armUSpringArmComponent
sphereUSphereComponent
capsuleUCapsuleComponent
boxUBoxComponent
audioUAudioComponent
sceneUSceneComponent
rotate_movementURotatingMovementComponent
moveUMovementComponent

You can also write component mesh: static_mesh and refer to mesh later in code.

Low-level: component UType "Name"​

In low-level style the name is quoted (unquoted names fail to parse):

uclass AExampleTurret : AActor meta: api=MYGAME_API
{
component UStaticMeshComponent "GunMesh"
component UCameraComponent "ViewCamera"

ctor {
RootComponent = GunMesh;
// or attach to a root: GunMesh->SetupAttachment(RootComponent);
}
}

Then configure it in the constructor with SetupAttachment, AddLocalOffset, SetRelativeRotation, etc.:

ctor {
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
AudioComp = CreateDefaultSubobject<UAudioComponent>(TEXT("Audio"));
AudioComp->SetupAttachment(RootComponent);
AudioComp->SetRelativeLocation(FVector(0, 0, 40));
}

Ownership model​

component member: type in high-level style always produces a VisibleAnywhere + CreateDefaultSubobject member. In low-level style you control everything yourself with component UType "Name" and explicit constructor wiring.

A full high-level example​

class rotating_cube extends actor meta: api=MYGAME_API
{
component cube: static_mesh
component rotator: rotate_movement

edit rotation_speed: number = 90.0

when_begin {
rotate_movement.RotationRate = FRotator(0, rotation_speed, 0);
}
}

Next: USTRUCT, UENUM & Interfaces.