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

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.

323808-outliner.png

When I move the TankPawn though my Turret stays behind.

323809-detatch.png

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?

Do you did it in multiplayer ?

Just working on a single player implementation currently.

According to you’r answer,
this look like ownership issue.

Try in blueprint to display the current owner (to see from server and client point of view).
When you give ownership to something, you should give it from the server.

Figured out my issue here. The StaticMesh that I was trying to connect to was in the parent class.
By using Super::BaseMesh instead of BaseMesh it seemed to solve all the problems I was having.

Thanks _Aherys for your responses, it helped.

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