Hi, I’m doing something to create and modify (in the editor only) a USkeletalMesh asset that USkeletalMeshComponents are using in the scene. Without calling PreEditChange, the ‘create’ part works fine (i do it in PostLoad of my custom Asset), but once i start modifying (in PostEditChangeProperty of my custom Asset), I get assertion failures and crashes in the rendering code, which is understandable since I’m “pulling the rug” of the rendering assets while they’re being rendered. So, to properly clear the rendering data out, i call PreEditChange(NULL) on the USkeletalMesh, then PostEditChange() after im done modifying. This should recreate all it’s rendering data (and, by browsing the code, also refresh all USkinnedMeshComponents which use it), but my mesh is still invisible. I even tried doing what FbxImporter does and using FComponentReregisterContext after PostEditChange on the components that use it, but that changes nothing.
How do i properly revive my mesh after changes ?
Here is my code:
USkeletalMesh* targetMesh = GetGeneratedMesh(); //this retrieves a TSubobjectPtr USkeletalMesh that this Asset owns.
//mergeMeshes is a TArray<USkeletalMesh*> of existing, proper USkeletalMeshes
TArray<FSkelMeshMergeSectionMapping> emptySections;
FSkeletalMeshMerge merger(targetMesh,mergeMeshes,emptySections,0);
targetMesh->PreEditChange(NULL); //if i comment this line out, then the mesh appears properly on load, but crashes/asserts the editor on change
const bool mergeStatus = merger.DoMerge();
check(mergeStatus == true);
targetMesh->PostEditChange(); //also comment this one out with PreEditChange
// Now iterate over all skeletal mesh components re-initialising them.
// This shouldn't be necessary because USkeletalMesh::PostEditChange does it internally ?
for (TObjectIterator<USkeletalMeshComponent> It; It; ++It)
{
USkeletalMeshComponent* SkelComp = *It;
if (SkelComp->SkeletalMesh == targetMesh && SkelComp->GetScene())
{
FComponentReregisterContext ReregisterContext(SkelComp);
}
}