RealDocs

AActor::K2_AttachToComponent

function Engine Blueprint Since 4.12
#include "GameFramework/Actor.h"
Access: public Specifiers: UFUNCTIONBlueprintCallable

Description

Attaches this actor's root component to a given scene component, with fine-grained control over how transform rules are applied. Returns true on success. This is the Blueprint-callable version of AttachToComponent().

Caveats & Gotchas

  • • Welding physics bodies (bWeldSimulatedBodies=true) transfers collision shapes into the parent and can cause permanent physics changes that persist after detaching — only weld when the attached actor will never need to simulate independently again.
  • • The target component must be registered (i.e. the actor must be in the world and its components initialized); calling this in a constructor or before BeginPlay on an unregistered component will fail silently.
  • • KeepWorld vs SnapToTarget rules produce very different results at runtime — SnapToTarget zeros out the relative transform, which may visually teleport the actor if it wasn't already at the socket.

Signature

ENGINE_API bool K2_AttachToComponent(USceneComponent* Parent, FName SocketName, EAttachmentRule LocationRule, EAttachmentRule RotationRule, EAttachmentRule ScaleRule, bool bWeldSimulatedBodies);

Parameters

Name Type Description Default
Parent USceneComponent* The component to attach this actor's root component to. —
SocketName FName Optional socket on the parent component to attach to. —
LocationRule EAttachmentRule How to handle the actor's translation when attaching. —
RotationRule EAttachmentRule How to handle the actor's rotation when attaching. —
ScaleRule EAttachmentRule How to handle the actor's scale when attaching. —
bWeldSimulatedBodies bool Whether to weld simulated physics bodies together on attach. true

Return Type

bool

Example

Attach a weapon actor to a character's hand socket C++
AWeapon* Weapon = GetWorld()->SpawnActor<AWeapon>(WeaponClass);
if (Weapon)
{
    Weapon->K2_AttachToComponent(
        GetMesh(),
        FName("hand_r_socket"),
        EAttachmentRule::SnapToTarget,
        EAttachmentRule::SnapToTarget,
        EAttachmentRule::KeepRelative,
        false
    );
}

Version History

Introduced in: 4.12

Version Status Notes
5.6 stable —

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.