Why is my actor location 0 after spawning at runtime?

Why are you using both SetActorLocation and SetActorRelativelocation in same time? Also ahy don’t you use ()->SpawnActor() to spawn?

I’m trying to spawn actor in game. For testing it is very simple:

	HitLocation.ImpactPoint.Z += Height;
	FTransform SpawnTM(FRotator(0, 0, 0), HitLocation.ImpactPoint);
	
	ARPGProjectileSpawner* spawner = Cast<ARPGProjectileSpawner>(UGameplayStatics::BeginSpawningActorFromClass(PowerOwner, effectActor, SpawnTM));
	if (spawner)
	{
		spawner->SetActorLocation(HitLocation.ImpactPoint);
		spawner->SetActorRelativeLocation(HitLocation.ImpactPoint);
		UGameplayStatics::FinishSpawningActor(spawner, SpawnTM);
	}
}

It works, and actor spawn in correct position.

No in that spawned actor I try to get location:

FVector currentLocation = GetActorLocation();
DrawDebugSphere((), currentLocation, Radius, 32, FColor::Yellow, false, 10.0f);

And GetActorLocation() return 0 vector.

#Regular SpawnActor?

For comparison, what happens if you use regular ole’ SpawnActor?

FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail 		= true;
SpawnInfo.Owner 				= this;
SpawnInfo.Instigator				= NULL;
SpawnInfo.bDeferConstruction 	= false;
 
return ()->SpawnActor<ARPGProjectileSpawner>(PowerOwner, HitLocation.ImpactPoint ,FRotator::ZeroRotator, SpawnInfo );

The issue with SpawnActor is, it can’t spawn Actor from TSubclassOf actor.

And I have some parts of my actor defined in blueprint.

Ah nvm, my previous comment, It take SubclassOf.
But the issue is, I need to spawn actor in Level, and when using SpawnActor, mesh I added to blueprint, doesn’t spawn.

But even if, the location vector is still 0.

I am not sure

but if you want to spawn a BP version of a base class

you should check out my templated spawn code

#Templated Spawn BP Wiki

The BP spawned, but the issue of wrong location remained. It still spawn in 0,0,0 location.

Hmmm this could be related to root component :> again why call setactrorelativelocation?

The issue was that I called even in wrong function, and it was called before location has been set.

It should have been called in OnConstruction.