USkeletalMesh RegisterMorphTarget does not work from 4.26 to 5.0EA?

Hello,

We are using a custom skeletal mesh importer for our crowd plugin character format.
We need to use USkeletalMesh::RegisterMorphTarget() to register “blendshapes”. However, since 4.26 this method can only register ONE morph target, then the new FSkeletalMeshRenderData::Cache() system “restores” the 1 target array from derivedData and replace the 2 targets array we have just added. Here is a call stack (from UE 5.0EA) :

> UnrealEditor-Engine.dll!FSkeletalMeshRenderData::Cache(const ITargetPlatform * TargetPlatform, USkeletalMesh * Owner) Line 176 C++
UnrealEditor-Engine.dll!USkeletalMesh::CacheDerivedData() Line 3776 C++
UnrealEditor-Engine.dll!USkeletalMesh::Build() Line 1776 C++
UnrealEditor-Engine.dll!USkeletalMesh::PostEditChangeProperty(FPropertyChangedEvent & PropertyChangedEvent) Line 1264 C++
UnrealEditor-CoreUObject.dll!UObject::PostEditChange() Line 351 C++
[Inline Frame] UnrealEditor-Engine.dll!FScopedSkeletalMeshPostEditChange::{dtor}() Line 362 C++
UnrealEditor-Engine.dll!USkeletalMesh::InitMorphTargetsAndRebuildRenderData() Line 2984 C++
UnrealEditor-Engine.dll!USkeletalMesh::RegisterMorphTarget(UMorphTarget * MorphTarget, bool bInvalidateRenderData) Line 3024 C++

where you can check that Owner->MorphTargets is reset from 2 to 1 each time RegisterMorphTarget is called after first one.

We can prevent this behavior by using this piece of code before registering the MorphTargets :

#if ((ENGINE_MAJOR_VERSION == 4) && (ENGINE_MINOR_VERSION == 26))
SkeletalMesh->UseLegacyMeshDerivedDataKey = true;
#elif ((ENGINE_MAJOR_VERSION == 4) && (ENGINE_MINOR_VERSION > 26) || (ENGINE_MAJOR_VERSION > 4))
SkeletalMesh->SetUseLegacyMeshDerivedDataKey(true);
#endif

However it seems that RegisterMorphTarget returns true on subsequent calls where as it does not properly register new targets in the SkeletalMesh. This seems to be a bug, I did not find any issue related to it in the tracker.

1 Like

Submit it as a pull request?

It looks like it is not intended to be used like this, as the renderData cache should not “void” the addition of a new MorphTarget. I would prefer that UE developers patch this behavior, so that the cache is recomputed when adding MorphTargets, to keep the benefit of the renderData cache.

I don’t know this part of UE sufficiently to do it myself, and would not have any guarentee that hit would it the release if it was done.

The code snippet is just a quick workaround if someone bumps on the same case.

1 Like