Spawned Actor not attached until I click on it in World Outline

CMDRRithwald
Thu, 03 Dec 2020 15:54:59 +0000
Blueprint

Hi All,

New to UE4 and I’m having an issue with spawning an actor and attaching it to my pawn.

I have a TankPawn, and when the game loads, I spawn a Turret, and attach it to a socket on the TankPawn’s StaticMesh.

void APlayerVehicle::SetTurret() {
	if (TurretClass)
	{
		FName SocketName = TEXT("TurretSocket");
		Turret = GetWorld()->SpawnActor<ATurretBase>(TurretClass);
		Turret->AttachToComponent(BaseMesh, FAttachmentTransformRules::KeepRelativeTransform, SocketName);
		Turret->SetOwner(GetOwner());
	}
}

I see the Turret, and its nested under the BaseMesh of my TankPawn.

When I move the TankPawn though my Turret stays behind.

However If I start the game and then click on the Turret in the World Outliner and then try to move, the Turret stays on my TankPawn, and rotates as I’d expect

Any idea of what I’m doing wrong?

5 posts - 1 participant