MetaHuman Python API - Add Ability To Edit MetaHuman Creator Assets In Place

Hi,

I’m currently using the python api to conform meshes and add custom textures.

I noticed however that if I try to edit them in place after I have rigged them Unreal crashes.

Looking at the examples on how to edit these assets, they all involve deleting the asset after export.

It seems to me that it’s connected to the fact that the asset is already rigged but I don’t see a way undo the rigging on the asset via python.

Is there a way to do this? Perhaps it’s a deeper issue which is why all the examples involve deleting the asset after?

Thanks

Robert

Hi Robert,

Would you be able to share a cut down version of the script that you’re using? I’d like to be able to reproduce the crash if possible, so I can take a look in more detail at what’s going wrong. I’ll need to check with the dev team about the expectation around editing the assets in place, but at the very least, we shouldn’t be crashing.

Thanks,

Euan

Hi Euan,

Before that can you check if there is a call in the Python API to Remove Rig

I suspect that to be the cause and I would like to test that first.

Thanks,

Robert

No, unfortunately, that isn’t exposed in 5.7. It’s similar to the discussion we had a little while back, where the API that’s exposed to python/bp has been expanded in 5.8. In this case, you’d need to make the following engine modification (in MetaHumanCharacterEditorSubsystem.h) to expose it in 5.7, or add a blueprint function library call that wrapped it:

	/**
	 * Remove the face rig from InCharacter, reverting the face mesh back to the
	 * archetype DNA and unregistering any morph targets.
	 *
	 * @param InCharacter Character to remove the face rig from. No-op if null.
	 */
	UFUNCTION(BlueprintCallable, Category = "MetaHuman|Auto-Rigging")
	void RemoveFaceRig(UMetaHumanCharacter* InCharacter);

So are you saying then that it’s exposed by default in 5.8 then?

Yeah, RemoveFaceRig is exposed in 5.8. That’s what the Remove Rig UI calls through to when dealing with a face rig. I see that RemoveBodyRig hasn’t been exposed though, so I’ll follow up with the dev team about that. It seems like an oversight. Would removing the face rig give you what you need?

Just looking at this again - RemoveFaceRig will also call RemoveBodyRig, so in 5.8 the behaviour should be the same when calling that directly from Python vs the UI.

I’m not sure. I guess whatever is the opposite of metahuman_subsystem.request_auto_rigging

It looks like it rigs both so I would need body as well. Why separate the functions like that? Is there a scenario where I would want that?

Oh okay thanks for the information

Hi, sorry for the delay following up on this. I’ve been out of office a fair amount this week so I’m just catching back up now.

I took another look at these functions and which are/aren’t exposed to python in 5.8. The reason for my confusion previously about whether RemoveFaceRig also calls RemoveBodyRig is that there are two different implementations of RemoveFaceRig. One lives in UMetaHumanCharacterEditorSubsystem, which is exposed in 5.8, and the other lives in FMetaHumanCharacterEditorToolkit, which is not exposed. Only the implementation in FMetaHumanCharacterEditorToolkit also calls RemoveBodyRig, the implementation in UMetaHumanCharacterEditorSubsystem doesn’t.

So in 5.8 my previous message was actually correct, you can’t remove the body rig. I’ve asked the dev team about this, and if there’s a particular reason for it not being exposed, but I assume this is just an oversight.

> I’m not sure. I guess whatever is the opposite of metahuman_subsystem.request_auto_rigging

If you were able to call both RemoveBodyRig and RemoveFaceRig, that would effectively be the opposite of calling RequestAutoRigging

Hi, sorry for the delay in following up with you on this. I’ve been out of office with Fest and then our offices being closed for a few weeks. In the end, I put together a script that attempted to do what you wanted and confirmed that it isn’t possible in the 5.8.0 release for the reasons that we discussed (UMetaHumanCharacterEditorSubsystem::RemoveBodyRig not being exposed to python).

The dev team agree that this should be exposed, but they want to make the change themselves. They are targeting the 5.8.2 hotfix for making the change, but that assumes it’s compliant with our hotfix rules so I can’t guarantee it’ll be included in that release. But once it is available, you should be able to do something like this to a pre-rigged character.

    skeletal_mesh = unreal.load_asset(
       "/Game/MetaHumans/Kellan/Male/Medium/NormalWeight/Body/m_med_nrw_body.m_med_nrw_body"
    )
                     
    metahuman_subsystem.remove_face_rig(character)
    metahuman_subsystem.remove_body_rig(character)
     
    body_vertices, body_indices = metahuman_subsystem.get_mesh_data_for_conforming(skeletal_mesh)
    if not body_vertices or not body_indices:
        unreal.log_error("get_mesh_data_for_conforming returned empty data")
        
    # Build conform target params
    conform_params = unreal.ConformTargetParams()
    conform_params.conform_target_mesh.target_parts_type = unreal.TargetPartsType.BODY_ONLY
    conform_params.conform_target_mesh.body_vertices = body_vertices
    conform_params.conform_target_mesh.body_vertex_indices = body_indices
    
    target_mesh_key = unreal.MetaHumanCharacterTargetMeshKey()
    target_mesh_key.body_mesh = skeletal_mesh
    success = metahuman_subsystem.conform_to_target_meshes(
        character, target_mesh_key, conform_params
    )

Awesome! Thanks for the follow up.

I also haven’t had a chance to loop back around to this so thanks for saving me some frustration.

No problem, glad that was helpful.

I’ve checked in on the status of the issue, and it seems that the team aren’t able to include it in a hotfix, so it’ll go into the next full release instead. The only other option in the meantime would be if you’re able to modify the engine source to expose the method to blueprint/python as I mentioned previously in the thread.

I’m going to close out this issue since it’s just waiting on the dev team now, but if you want to discuss it any further, feel free to reopen it. Thanks again for the feedback on this.