CToolComponent

Overview

Runtime creation and retrieval of UObjects, Actors, Components (Actor, Scene, Primitive), Niagara effects, and DataTables.

Object & Actor creation

Name Description
createObjectAtRuntime Create a UObject at runtime with optional init lambda. Overloads with/without explicit UClass.
createObjectSingletonAtRuntime Create only if ref is not already valid.
spawnActorAtRuntime Deferred spawn with init before FinishSpawning. Supports attach to owner. Overloads with/without explicit UClass.
spawnActorSingletonAtRuntime Spawn only if ref is not already valid.
createDatatableAtRuntime Create a UDataTable for a struct type at runtime.
// Create a UObject
UCPerf* perf = createObjectAtRuntime<UCPerf>(this, [](UCPerf* p) { /* init */ });

// Create singleton (only if not already valid)
createObjectSingletonAtRuntime<UCPerf>(this, perf);

// Spawn actor with init before BeginPlay
AMyActor* a = spawnActorAtRuntime<AMyActor>(this, FTransform::Identity, [](AMyActor* a) {
    a->MyProperty = 42;
});

// Create datatable
UDataTable* dt = createDatatableAtRuntime<FMyRow>();

Component creation

Name Description
createActorComponentAtRuntime Create, register, and add an ActorComponent at runtime.
createSceneComponentAtRuntime Create and attach a SceneComponent.
createPrimitiveComponentAtRuntime Create and attach a PrimitiveComponent with collision settings.
// ActorComponent
UMyComponent* c = createActorComponentAtRuntime<UMyComponent>(myActor);

// SceneComponent attached to parent
USceneComponent* s = createSceneComponentAtRuntime<USceneComponent>(parentComponent, EComponentMobility::Movable);

// PrimitiveComponent with collision
UStaticMeshComponent* p = createPrimitiveComponentAtRuntime<UStaticMeshComponent>(
    parentComponent, ECollisionEnabled::QueryAndPhysics, EComponentMobility::Movable);

Component retrieval

Name Description
retrieveComponentNoCast Get first component matching class or interface, returned as UActorComponent* (no cast). Tries GetComponentsByInterface first, then GetComponentByClass.
retrieveComponent Get first component of type C on actor. Casts the result.
executeComponent Retrieve component and execute lambda on it. Multiple overloads for class/interface combinations.
// Retrieve (no cast, returns UActorComponent*)
UActorComponent* raw = retrieveComponentNoCast<IMyInterface>(myActor);

// Retrieve (cast to C*)
UMyComponent* c = retrieveComponent<UMyComponent>(myActor);

// Execute on component
executeComponent<UMyComponent>(myActor, [](UMyComponent* c) {
    c->DoSomething();
});

// Execute with interface cast
executeComponent<UMyComponent, IMyInterface>(myActor, [](UActorComponent* c, IMyInterface* i) {
    i->InterfaceMethod();
});

Niagara

Name Description
spawnNiagaraAtRuntime Spawn Niagara effect. Overloads: attached to component, or at world location.
// Attached to actor
spawnNiagaraAtRuntime(myActor, niagaraSystem, attachComponent, FName("Socket"), FRotator::ZeroRotator, FVector(1), true);

// At world location
spawnNiagaraAtRuntime(GetWorld(), niagaraSystem, FVector(100, 200, 0));