AActor::SetActorLocation
#include "GameFramework/Actor.h"
Access: public
Description
Sets the world-space location of the actor. If bSweep is true, the movement will collide with the world and stop at the first blocking hit, returning false if blocked.
Signature
bool SetActorLocation(const FVector& NewLocation, bool bSweep = false, FHitResult* OutSweepHitResult = nullptr, ETeleportType Teleport = ETeleportType::None) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| NewLocation | const FVector& | The desired new world-space location. | — |
| bSweep | bool | If true, sweeps through physics and stops at the first blocking hit. | false |
| OutSweepHitResult | FHitResult* | If sweep is enabled, populated with the hit result. | nullptr |
| Teleport | ETeleportType | Whether to teleport physics state (ResetPhysics) or maintain velocity (None). | ETeleportType::None |
Return Type
bool Caveats & Gotchas
- • Returns true if the move was fully completed, false if blocked by a sweep collision.
- • Using `ETeleportType::TeleportPhysics` is required when teleporting physics-simulated actors to avoid incorrect velocity transfer.
- • In multiplayer, location changes on the server are automatically replicated if `bReplicateMovement` is true.
Example
Teleporting an actor C++
// Instant teleport, no collision check
MyActor->SetActorLocation(FVector(0.f, 0.f, 500.f));
// Sweep: stop at first obstacle
FHitResult Hit;
bool bMoved = MyActor->SetActorLocation(TargetLocation, true, &Hit);
if (!bMoved)
{
UE_LOG(LogTemp, Warning, TEXT("Blocked by: %s"), *Hit.GetActor()->GetName());
} Tags
Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?