SetActorLocation does not move the actor

I have a class derived from Actor.
I need to move the actor to a specific location after spawn.
The location is changed but the actor is not moving, even if I check the current actor location.
Why the actor’s location isn’t reflected within the level ?

AKGuidedActor::AKGuidedActor(const FObjectInitializer& ObjectInitializer) 
	: Super(ObjectInitializer)
{
	// Create a scene component to be able to size the actor
	SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
	RootComponent = SceneComponent;

	// Create the mesh component
	StaticMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("StaticMesh"));
	// Turn physics and gravity on
	StaticMesh->SetSimulatePhysics(true);
	StaticMesh->SetEnableGravity(true);
	StaticMesh->AttachTo(RootComponent);

	// The object type for collision
	StaticMesh->SetCollisionObjectType(ECC_WorldDynamic);
	StaticMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	StaticMesh->SetCollisionResponseToAllChannels(ECR_Block);
	StaticMesh->SetCollisionResponseToChannel(COLLISION_WEAPON, ECR_Block);
	StaticMesh->SetCollisionResponseToChannel(COLLISION_PROJECTILE, ECR_Block);
	StaticMesh->SetCollisionResponseToChannel(COLLISION_SPELL, ECR_Block);

	StaticMesh->AlwaysLoadOnClient = true;
	StaticMesh->AlwaysLoadOnServer = true;
	StaticMesh->bTraceComplexOnMove = true;

	// Create the base collision component to handle the object's collision
	BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
	BaseCollisionComponent->InitSphereRadius(100.0f);
	BaseCollisionComponent->AttachTo(RootComponent);

	BaseCollisionComponent->SetCollisionObjectType(ECC_WorldDynamic);
	BaseCollisionComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
	BaseCollisionComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
	BaseCollisionComponent->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);

	// Enable collision to be able to move the actor
	SetActorEnableCollision(true);

	SetReplicates(true);
	SetReplicateMovement(true);
	ExplosionDamage = 0;
	ExplosionRadius = 0.0f;
	LifeTime = 0.0f;

	// Allow tick to move this guided actor
	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bAllowTickOnDedicatedServer = true;

}

In the tick function, I move the actor.

void AKGuidedActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	UE_LOG(LogKSGMWeapon, Verbose, TEXT("AKGuidedActor::Tick  -  Role=%s"), NETROLETOSTRING(Role));
	FTransform const ActorTransform = GetTransform();

	FVector TickLocation = TargetTransform.GetLocation() * DeltaTime;
	UE_LOG(LogKSGMWeapon, Verbose, TEXT("AKGuidedActor::Tick  -  DeltaTime=%f    TargetTransform.GetLocation()=%s    ActorLocation=%s     TickLocation=%s"), DeltaTime, *TargetTransform.GetLocation().ToString(), *ActorTransform.GetLocation().ToString(), *TickLocation.ToString());
	SetActorLocation(TickLocation + ActorTransform.GetLocation());
}

If I check the log, the actual actor location is changing ( ActorLocation=X= Y= Z=), but the actor is not moving within the level.

[2016.05.11-07.09.43:502][288]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:502][288]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=950.000 Y=-400.000 Z=-58.527     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:513][289]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:513][289]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=999.988 Y=-406.082 Z=-60.599     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:531][290]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:531][290]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=1049.977 Y=-412.165 Z=-62.672     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:546][291]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:546][291]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=1099.965 Y=-418.247 Z=-64.744     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:562][292]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:562][292]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=1149.953 Y=-424.330 Z=-66.817     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:578][293]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:578][293]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=1199.942 Y=-430.412 Z=-68.890     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:596][294]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority
[2016.05.11-07.09.43:596][294]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  DeltaTime=0.016129    TargetTransform.GetLocation()=X=3099.276 Y=-377.115 Z=-128.500    ActorLocation=X=1249.930 Y=-436.495 Z=-70.962     TickLocation=X=49.988 Y=-6.082 Z=-2.073
[2016.05.11-07.09.43:610][295]LogKSGMWeapon:Verbose: AKGuidedActor::Tick  -  Role=ROLE_Authority

What I’m doing wrong ?

D.

You have you StaticMesh component set physics enabled, partially this means that you can’t directly move this actor. Yes, actor location will change, but mesh will not, it has it’s own basis what not depends on SceneComponent.
You even can track it down: watch for two components: StaticMesh and BaseCollisionComponent - the first one will be static, the second one will move with actor (if it hasn’t it’s physics turned on).
If you want to move StaticMesh (what is only visible component) you need to make it RootComponent, that’s all.

Hello domzorg ,

make sure your actor is set to be mobile and not static in the mobility section of in your level editor.

“DeltaTime” is an extremly small value, around 1/30 to 1/60 depending on your frame rate, and your are scaling your actor’s position with it which makes "TickLocation " nearly a zero vector. I assume the actor you tested this on is around the world’s origin which means get actor location will return a vector with very small values for x, y, and z, which worsens the effect.

For demonstrational purposes, I recommend you do SetActorLocation(FVector(500.f, 500.f, 500.f)) or some other hard coded value to see for yourself that is works.

Cheers,
Univise

Effectively I’ve discovered that moving the mesh works.
I’m using SetComponentLocation on the mesh and it works.

Txs for the explanations.

Yes I’ve changed the way of moving. I’m using a lerp between the initial position and the target position function of the time.
And it works.

Txs for pointing it out.