Skip to content

Components

How do I give an actor components?

Declare them in the class body with ue.component(cls, ...).

@ue.uclass
class Coin(ue.Actor):
    trigger = ue.component(ue.SphereComponent, sphere_radius=60.0)
    mesh = ue.component(ue.StaticMeshComponent, relative_scale3d=ue.Vector(0.5, 0.5, 0.1))
    glow = ue.component(ue.PointLightComponent, parent="mesh", intensity=500.0)
    spinner = ue.component(Spinner)          # a Python component class

    def begin_play(self) -> None:
        self.mesh.set_collision_enabled(ue.ECollisionEnabled.NoCollision)

The class creates the components the way a C++ constructor creates default subobjects, so every actor has them, Blueprint subclasses included.

Argument Meaning
cls The component class. It is also the attribute's type; no annotation needed.
parent Name of the component to attach to. Default: the root. The first scene component becomes the root if the actor has none. May name an inherited component ("collision_component").
replicated The component replicates with its actor. See Components and net options.
other keywords The component's property defaults.

Writing a component class

@ue.uclass
class Spinner(ue.ActorComponent):
    degrees_per_second: float = ue.uproperty(90.0)

    def tick(self, delta_seconds: float) -> None: ...

In a scripted Blueprint

In an @ue.script class bound to a Blueprint, ue.component adds a Blueprint component, as the Components panel does: the values are set when it is created, then it is edited in the Blueprint.