ue-actor-component-architecture

Use this skill when working with Actor and component design in Unreal Engine. Triggers on: Actor, component, BeginPlay, Tick, SpawnActor, lifecycle, CreateDefaultSubobject, composition, EndPlay, PostInitializeComponents, UActorComponent, USceneComponent, UINTERFACE, attachment, spawn, interface. See

By quodsoler · 870 installs

npx skills add quodsoler/unreal-engine-skills --skill ue-actor-component-architecture

Source repository · Upstream listing

UE Actor Component Architecture You are an expert in Unreal Engine's Actor Component architecture. Project Context Before responding, read .agents/ue project context.md for the project's subsystem inventory, coding conventions, and any existing actor hierarchies or component patterns. This tells you which base classes are established and what naming conventions apply. Information Gathering Clarify the developer's specific need before diving in: New actor from scratch, or adding behavior to an existing one? Logic only (UActorComponent) or needs world position (USceneComponent)? Spawning requirement (deferred init, pooling, net spawned)? Lifecycle bug (BeginPlay/Constructor confusion, component not initialized)? Cross actor behavior via interfaces? Core Architecture Mental Model Unreal's Actor Component system is composition over inheritance . An AActor is a container that owns components. Behavior, rendering, collision, and logic are all expressed through UActorComponent subclasses. AActor is a full UObject — never new / delete an actor. Always use SpawnActor and Destroy . Actor Lifecycle Full event order and safety rules are in references/actor lifecycle.md . Key sequence: Constructor vs BeginPlay Constructor runs first on the Class Default Object (CDO) — an archetype used for default values. GetWorld() returns nullptr on the CDO. Never access the world or other actors in the constructor. PostInitializeComponents Called before BeginPlay; components are initialized; world exists. Use it to bind delegates to own components. EndPlay — reasons matter Reason When Destroyed Actor Destroy() called explicitly LevelTransition Map change EndPlayInEditor PIE session ended RemovedFromWorld Level streaming unloaded the sublevel Quit Application shutdown Network lifecycle note Replicated actors : on clients, BeginPlay may fire before all replicated properties arrive. Use OnRep callbacks for initialization that depends on replicated state. PostNetReceive() fires after each replication update (including the initial one); guard one time setup inside it with a bHasInitialized flag. PostNetInit is not a standard AActor virtual and should not be used as a general init hook. Component System The three layers Class Transform Rendering/Collision Use for UActorComponent No No Pure logic — health, inventory, AI data USceneComponent Yes No Transform anchors, grouping, pivot points UPrimitiveComponent Yes Yes Meshes, shapes, anything visible or collidable Notable subclasses : UStaticMeshComponent , USkeletalMeshComponent , shape primitives ( UCapsuleComponent , UBoxComponent , USphereComponent ), UWidgetComponent (3D UI in world space — requires "UMG" module), USpringArmComponent + UCameraComponent , UChildActorComponent . See references/component types.md . Component creation In the constructor (for default components that appear in the Details panel): At runtime (dynamic addition): Why this distinction matters: constructor created components are owned subobjects and participate in the actor's GC root. Runtime components via NewObject are not automatically serialized unless you add them to a UPROPERTY array. Attachment Activation Spawning Standard spawn Deferred spawning — configure before BeginPlay Use when the actor's BeginPlay reads data that must be set before it runs. Object pooling For high frequency actors (projectiles, shell casings), repeated SpawnActor / Destroy creates GC pressure. Pool them: pre spawn, hide + disable collision to "return," re enable to "reuse." Ticking Setup Tick groups: TG PrePhysics (default, input/movement) → TG DuringPhysics (physics coupled logic, runs during physics step) → TG PostPhysics (camera, IK) → TG PostUpdateWork (final reads). Component tick : Set PrimaryComponentTick.bCanEverTick = true in the component constructor, with PrimaryComponentTick.TickGroup for ordering — same API as actor tick. Tick dependencies When NOT to tick Tick has per frame cost even when nothing changes. Prefer: Only tick for true per frame needs: smooth interpolation, physics sub stepping, streaming queries. Interfaces (UINTERFACE Pattern) Interfaces let unrelated actor types respond to the same message without coupling through inheritance. This replaces Cast<ASpecificType scattered across your codebase. Declaration Implementation Calling through the interface Interface vs component : use an interface for a capability declaration ("this can be interacted with") especially when Blueprint classes need to implement it. Use a component when the behavior has its own state, needs ticking, or is reused identically by many actor types. Composition Patterns Favor components over deep inheritance Component to component communication Components should not hold raw pointers to siblings. Query through the owner or use delegates: Data driven composition Common Mistakes and Anti Patterns Inheritance abuse Tick polling instead of events Forgetting Super in lifecycle overrides Every lifecycle override must call Super:: . Skipping it breaks replication, GC, and Blueprint event forwarding. Storing raw actor pointers Related Skills ue cpp foundations — UCLASS, UPROPERTY, UFUNCTION macros underpinning all patterns above ue gameplay framework — GameMode, PlayerController, Pawn layered on top of this system ue physics collision — UPrimitiveComponent channels, sweeps, overlap events Quick Reference