RealDocs

AActor::K2_AttachToActor

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

Description

Attaches this actor's root component to the root component of another actor. Internally delegates to AttachToActor() with an FAttachmentTransformRules struct. Returns false if either actor is invalid or unregistered.

Caveats & Gotchas

  • Unlike K2_AttachToComponent, this always targets the parent actor's root component — if you need to attach to a non-root component (e.g. a specific mesh socket), use K2_AttachToComponent instead.
  • On network games, attachment is replicated via AttachmentReplication only when the actor has bReplicates=true. Attaching on a client without authority won't replicate to the server.
  • Welded physics bodies may accumulate permanent mass/shape changes in the parent's physics asset; consider detaching before simulating independently.

Signature

ENGINE_API bool K2_AttachToActor(AActor* ParentActor, FName SocketName, EAttachmentRule LocationRule, EAttachmentRule RotationRule, EAttachmentRule ScaleRule, bool bWeldSimulatedBodies);

Parameters

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

Return Type

bool

Example

Attach a pickup actor to a pawn at a named socket C++
// Attach a grenade actor to the player's right hand
AGrenade* Grenade = GetWorld()->SpawnActor<AGrenade>(GrenadeClass);
if (Grenade)
{
    Grenade->K2_AttachToActor(
        PlayerPawn,
        FName("hand_r"),
        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.