Virtual bones issues when loading skeletalmesh at runtime

Hi all !

I’m facing a very disturbing issue in the builds of our multiplayer game :

we have a class base on Character that contains a few components, including a third person mesh component (the game is first person, so this is used to show the player where it is not locally controlled)

In the constructor this mesh component has no skeletal mesh set, and no animation class set.
The meshes are stored in an array so we can choose which one we apply

from ACharacterBase.h :

	UPROPERTY(EditAnywhere)
	TArray<USkeletalMesh*> ThirdPersonMeshes;

At run time, I then set the mesh and the animation class :

void ACharacterBase::LoadSkin() {
	uint8 SkinId = GetPlayerState()->SkinId;

	check(ThirdPersonMeshes.Num() >= SkinId);
	USkeletalMeshComponent* ThirdPersonMesh = GetMesh();
	check(ThirdPersonMesh);
	ThirdPersonMesh->SetSkeletalMesh(ThirdPersonMeshes[SkinId - 1]);

	ThirdPersonAnimClass = ThirdPersonAnimationClass[SkinId - 1];
    // actually we use a short timer to make sure the mesh has been set properly otherwise we get a few warnings
    // but i didn't want to add unneeded details
	GetMesh()->SetAnimInstanceClass(ThirdPersonAnimClass);
}

We do this only once after some initialization, and we never change it afterwards.

In PIE this works fine, but when I cook my content, virtual bones don’t work anymore : instead of following the bones they’re related to, they are stuck at the origin point of the skeleton

This is not always happening, and it’s triggered by stuff totally unrelated (like adding a certain call in the level BP), but this seems very related to the fact that we set the skeletal mesh at runtime, after initialization.

I’m going to dig into the engine code, but if any of you have an idea about where this could come from, or if it is a known bug, tell me !

So after some digging, I found the following :

the problem arise before my LoadSkin method, when the ThirdPersonMeshes property is initialized from serialized data

in the PIE case everything goes fine, the RefSkeleton of the mesh is correctly set and I get my raw bones and virtual bones indexed

in the cooked build, the virtual bones are absent, so it seems there were not serialized, although there was no warning during the cooking

I can now confirm that the RefSkeleton is not serialized properly when cooked. The Skeleton is correct though, so I can fix my issue by rebuilding the RefSkeleton from the skeleton, but this comes from a bug from the engine / editor

It’s not always, and it’s triggered by totally unrelated modifications on the project, but once we are in a configuration that leads to this, every build will have the problem

this seems to be caused by issue Unreal Engine Issues and Bug Tracker (UE-66234)

It still hapens in 2021, despite they having fixed it in the past