AActor::SetActorLocation

Syntax

bool SetActorLocation
(
    const FVector & NewLocation,
    bool bSweep,
    FHitResult * OutSweepHitResult,
    ETeleportType Teleport
)

Remarks

Move the actor instantly to the specified location.

Returns

Whether the location was successfully set if not swept, or whether movement occurred if swept.

Parameters

Parameter

Description

NewLocation

The new location to teleport the Actor to.

bSweep

Whether we sweep to the destination location, triggering overlaps along the way and stopping short of the target if blocked by something. Only the root component is swept and checked for blocking collision, child components move without sweeping. If collision is off, this has no effect.

Teleport

How we teleport the physics state (if physics collision is enabled for this object). If equal to ETeleportType::TeleportPhysics, physics velocity for this object is unchanged (so ragdoll parts are not affected by change in location). If equal to ETeleportType::None, physics velocity is updated based on the change in position (affecting ragdoll parts). If CCD is on and not teleporting, this will affect objects along the entire swept volume.

OutSweepHitResult

The hit result from the move if swept.

Example Code

MyActor.cpp at line 94:

    // Get the current location  
    FVector ActorLocation = GetActorLocation();  
    // Move it slightly  
    ActorLocation.Z += 10.0f;  
    // Set the location- this will blindly place the actor at the given location  
    SetActorLocation( ActorLocation, false );  

MyActor.cpp at line 107:

    // Get the current location  
    FVector CurrentLocation = GetActorLocation();  
    // Move it slightly  
    CurrentLocation.Z += 1.0f;  
    FHitResult HitResult;  
    if( SetActorLocation(CurrentLocation, true, &HitResult) == false )  
    {  
        // If the set function returned false something is blocking at that location. We can interrogate this result to determine details of this  
        // @See FHitResult for more information  
        if( HitResult.GetActor() != nullptr)  
        {  
            UE_LOG( LogDocumentationCode, Warning, TEXT("Cannot move object to location, blocked by %s"), *HitResult.GetActor()->GetName() );  
        }         
    }  

See Also:

  1. [](FHitResult)

References

Module

Engine

Header

Runtime/Engine/Classes/GameFramework/Actor.h

Source

Runtime/Engine/Private/Actor.cpp