SetSkeletalMesh without resetting the ragdoll to default pose

Hi all!
In my code, I’m replacing a skeletal mesh of a USkeletalMeshComponent with a different skeletal mesh, using myMeshComponent->SetSkeletalMesh(newMesh,false). The component has a physics asset assigned and it is simulating physics, so basically it is in “ragdoll mode”. The problem is, that for the one frame in that the mesh gets replaced, the new mesh will show its default pose, resulting in an unpleasant graphical glitch. After that frame, the new mesh will synchronize with the physics asset and everything looks fine. I guess the problem is, that things are being done in the wrong order, something like this:

  1. Synchronize skeletal mesh with physics asset
  2. Replace Mesh
  3. Render

While it should probably be done in this order:

  1. Replace Mesh
  2. Synchronize skeletal mesh with physics asset
  3. Render

However, I have no idea how to trigger the replacement before the physics synchronization or after the rendering, or how to trigger the physics synchronization manually.
Here are the things that I already tried:

  • Replacing the mesh in the tick function and setting PrimaryActorTick.TickGroup = TG_PrePhysics; -> No effect
  • Calling myMeshComponent->MarkRenderStateDirty() after replacing the mesh -> No effect (it’s probably done by default anyway)
  • Calling myMeshComponent->GetPhysicsAsset()->RefreshPhysicsAssetChange() after replacing the mesh -> Results in a crash as soon as I try to reference something related to the physics asset

Maybe someone here has an idea how to solve this problem?

What about fixing the position with a snapshot before replacement, replacing, then removing the snapshot?

@MostHost LA: Thanks, I didn’t know about pose snapshots before. I created a snapshot using myMeshComponent->GetAnimInstance()->SavePoseSnapshot(“Temp”); and assigned an animation blueprint to the mesh, which simply links the snapshot “Temp” to the output pose. The mesh replacement is looking smooth now.
I’d still prefer it, if there was a way to do it without the animation blueprint and just in C++, but it’s a working solution, so thank you very much!

I mean, there may be other ways, I just don’t know them yet. That’s the first thing that came to mind…