Character actor visible for a frame after spawn even if set invisible

I’m creating a monster spawner that can play animations on the spawned monsters. The spawn animations are set up so that the root bone is on the ground and the mesh starts below the root and then animates up to idle.

The problem I’m having is that when the monster is spawned it is visible for a frame in its bind pose. I’ve tried setting it invisible immediately after calling SpawnActor and then using a custom animation notify to set the character visible, but it hasn’t helped. I’ve also confirmed that it’s not a problem from the character blending from bind into the spawn animation.

Here’s what my spawn code looks like:

   AMSCharacter* SpawnedMonster = GetWorld()->SpawnActor( CharacterToSpawn, SpawnLocation, SpawnRotation, SpawnParams );

	if( SpawnedMonster )
	{    
		if( SpawnMontage )
		{
			SpawnedMonster->GetMesh()->SetVisibility( false, true );
			SpawnedMonster->SetActorHiddenInGame( true );
			SpawnedMonster->SetSpawnAnimation( SpawnMontage );
		}

		++TotalSpawned;
	}

The visible bind frame appears about half the time when monsters spawn. Any idea how to get around this? I’ve thought about spawning the monsters at some distant point and then moving them into position when setting them visible, but I’m hoping for a better solution.

1 Like

Nevermind, I fixed it.

Just kidding, here’s the fix!

It wasn’t a problem with visibility or animation blending, it was a problem with animation updating. Spawning actors and setting them invisible worked fine, and the animation pose was being updated ok, but the bones weren’t being refreshed because the mesh wasn’t visible. When the mesh was set visible, the bones were still in bind for a frame before being updated, which created the flicker and made it appear that hiding the actor wasn’t working.

The fix:

GetMesh()->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::AlwaysTickPoseAndRefreshBones;

I set it back to the default, AlwaysTickPose, as soon as I could since this probably is not great for performance.