TransWikia.com

How to copy morphs from one SkeletalMesh to another in UE4?

Game Development Asked on January 29, 2021

I would like to enable modders to copy morphs from one SkeletalMesh to another.

I wrote simple Python script to do that. The inspiration came from here.

#Takes the last element of all selected stuff in the Content Browser
#Copies all morph targets from selection - excluding the last element - to the last element

#array = [ from1,from2,from3, ... , lastElementThatTakesAll]


import unreal as ue
from unreal import SkeletalMesh, MorphTarget

# create unreal class instances
editor_util = ue.EditorUtilityLibrary()
#material_util=unreal.Material()

# get the selected assets
selected_assets = editor_util.get_selected_assets()

lastmesh=selected_assets[len(selected_assets)-1]

morphtargets=lastmesh.morph_targets
print("lastmesh morphs: ")
print(lastmesh.morph_targets)

for morphlist in selected_assets:
    if(morphlist==lastmesh):break
    print("List: ")
    print( morphlist)
    for morph in morphlist.morph_targets:
        print("Morph: " )
        print(morph)
        morphtargets.append( morph)

lastmesh.morph_targets=morphtargets

It does work, I can see the sliders on the Receiver mesh in Persona…
The issue is it only works with duplicated meshes… Not very useful…
If I import the same mesh with different settings the morph target sliders don’t do anything, even though the mesh topology is identical.

I wrote BP node to do the same thing, but the results are the same… sliders are present, but aren’t doing anything.

bool UVictoryBPFunctionLibrary::AddMorphTargetToSkelMeshFromSkelMesh(USkeletalMesh* Receiver, USkeletalMesh* Sender) {
    auto senderMorphs = Sender->MorphTargets;

    for(auto morph : senderMorphs)
    {
        Receiver->MorphTargets.Add(morph);
    }

    return true;
}

I tried the RegisterMorphTarget function as well, but this one just crashed the editor.
Tried calling both in the construction script/beginplay as well.

bool UVictoryBPFunctionLibrary::AddMorphTargetToSkelMeshFromSkelMesh(USkeletalMesh* Receiver, USkeletalMesh* Sender) {
    auto senderMorphs = Sender->MorphTargets;

    for (auto morph : senderMorphs)
    {
        bool valid=Receiver->RegisterMorphTarget(morph,false);

        //GEngine->AddOnScreenDebugMessage(-1,15.0f,FColor::Red,"morph name:  "+morph->GetName());
    }
    return true;
}

EDIT:

This line causes the crash in the editor:

Receiver->InitMorphTargets();

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP