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.