AActor::GetDefaultAttachComponent
#include "GameFramework/Actor.h"
Access: public
Specifiers: virtual
Description
Returns the component that child actors and components should attach to by default. The base implementation returns the root component, but subclasses can override it to expose a different attachment point.
Caveats & Gotchas
- • When attaching via AttachToActor(), the engine calls this override on the parent actor to determine the actual attachment target. If you override this to return a non-root component, ensure the component is always valid, as null would silently detach the child.
- • Unlike GetRootComponent(), this is a virtual call and cannot be inlined; avoid calling it in tight loops where performance matters.
Signature
virtual USceneComponent* GetDefaultAttachComponent() const { return GetRootComponent(); } Return Type
USceneComponent* Example
Override to expose a dedicated attach socket C++
// AMyVehicle.h
USceneComponent* GetDefaultAttachComponent() const override;
// AMyVehicle.cpp
USceneComponent* AMyVehicle::GetDefaultAttachComponent() const
{
// Passengers attach to the seat socket component, not the root
return PassengerAttachPoint;
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?