components.create

Creates and initializes an actor component from a native or Blueprint class.

Top-level alias: ue.create_component.

Syntax

ue.components.create(
    actor: ActorReference,
    component_class: string | UObjectProxy,
    options?: table
) -> UObjectProxy?, string?

Parameters

ParameterTypeDescription
actorActorReferenceActor proxy, string query, or actor descriptor.
component_classstring | UObjectProxyNative/generated Blueprint UActorComponent class path or a UClass proxy.
options.manual_attachmentboolean?Skip Unreal's automatic root attachment. Default: false.
options.propertiestable?Reflected component properties to write immediately after creation.

Returns

TypeDescription
UObjectProxyThe newly created and registered component.
nil, stringValidation, creation, or property initialization failed.

Example

local character = assert(ue.get_player_character())

local light = assert(ue.create_component(
    character,
    "/Script/Engine.PointLightComponent",
    {
        properties = {
            Intensity = 5000,
            AttenuationRadius = 900
        }
    }
))

Use a generated class path ending in _C for Blueprint component classes.

If a property write fails, the new component is destroyed and the function returns nil, error; partially initialized components are not left on the actor.

Creation requires Unreal's reflected AActor.AddComponentByClass function. An engine version that does not expose it returns a descriptive error.

On this page