AActor::SetActorRelativeLocation
#include "GameFramework/Actor.h"
Access: public
Description
Sets the location of this actor's root component relative to its parent component in the attachment hierarchy. If the actor is not attached, the relative location equals world location.
Caveats & Gotchas
- • When the actor is not attached to anything, relative location equals world location — this makes SetActorRelativeLocation and SetActorLocation equivalent in that case, but code intent is clearer when you use the correct variant.
- • Only the root component is swept; child/attached components are moved without sweeping. If collision is disabled on the root, bSweep has no effect.
- • When teleporting without ETeleportType::TeleportPhysics, simulated child components are not repositioned. Pass TeleportPhysics if you need all physics bodies to follow.
Signature
ENGINE_API void SetActorRelativeLocation(FVector NewRelativeLocation, bool bSweep=false, FHitResult* OutSweepHitResult=nullptr, ETeleportType Teleport = ETeleportType::None) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| NewRelativeLocation | FVector | The new location of the actor's root component, relative to its parent component (or world origin if unattached). | — |
| bSweep | bool | If true, sweeps to the destination, stopping at blocking geometry. | false |
| OutSweepHitResult | FHitResult* | If provided and bSweep is true, receives the blocking hit. | nullptr |
| Teleport | ETeleportType | Controls physics state update: TeleportPhysics preserves velocity; None recalculates velocity from displacement. | ETeleportType::None |
Return Type
void Example
Offset an attached actor relative to its parent C++
// Move a weapon actor to a specific socket offset
SetActorRelativeLocation(FVector(0.f, 10.f, 5.f)); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?