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:
- Synchronize skeletal mesh with physics asset
- Replace Mesh
- Render
While it should probably be done in this order:
- Replace Mesh
- Synchronize skeletal mesh with physics asset
- 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?