1
$\begingroup$

I am currently working on exporting Rigify rigs to Unreal Engine 4. My starting point is this: https://github.com/chichige-bobo/BlenderPython/blob/master/RigifyToUnreal/RigifyToUnreal.py

which seemed to work in Blender pre-2.8.

I got quite far already. However, when switching back from EDIT mode to OBJECT mode in the script after having deleted bones in my armature, I am getting errors that I want to avoid.

Excerpt of my script:

import bpy, math

def main():
    initialSelection = bpy.context.selected_objects
    
    for obj in initialSelection:
        if obj.type == 'ARMATURE':
            rigifyObj = obj
    
    bpy.ops.object.mode_set(mode = 'OBJECT')
    bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False})

    newRigObj = bpy.context.object
    armature = newRigObj.data
    
    bpy.ops.object.mode_set(mode = 'EDIT')
    
    boneNames = [['root', None, False],

                ['DEF-spine', 'root', False],
                ['DEF-spine.001', 'DEF-spine', True],
                ['DEF-spine.002', 'DEF-spine.001', True],
                ['DEF-spine.003', 'DEF-spine.002', True],
                ['DEF-spine.004', 'DEF-spine.003', True],
                ['DEF-spine.005', 'DEF-spine.004', True]
                # , ...
                ]
    
    deleteBones = []
    for armBone in armature.edit_bones:
        isFound = False
        for boneName in boneNames:
            if armBone.name == boneName[0]:
                isFound = True
                break
            
        if not isFound:
            deleteBones.append(armBone)
    
    for deleteBone in deleteBones:
        armature.edit_bones.remove(deleteBone)
        
    bpy.ops.object.mode_set(mode = 'OBJECT')
    
################################################
print('############################################################')
main()
print('############################################################')

Error Log:

############################################################
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'ORG-spine.005', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.005', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'ORG-spine.004', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.004', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.004', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.004', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.003', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.003', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.002', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.002', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine.001', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Copy Transforms) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine', operation code: BONE_DONE))
add_relation(Copy Transforms) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Damped Track) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Damped Track) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
find_node_operation: Failed for (BONE_DONE, '')
add_relation(Stretch To) - Could not find op_from (OperationKey(type: BONE, component name: 'tweak_spine.001', operation code: BONE_DONE))
add_relation(Stretch To) - Failed, but op_to (OperationKey(type: BONE, component name: 'DEF-spine', operation code: BONE_CONSTRAINTS)) was ok
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - pose.bones["MCH-thigh_ik_target.parent.R"].constraints["SWITCH_PARENT"].targets[5].weight[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_upper_arm_ik_pole.R"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.R.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-forearm.R"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-forearm.R"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-upper_arm.L.001"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["thigh_ik_target.L"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_thigh_ik_pole.L"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-thigh.L.001"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L"].bbone_easeout[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["DEF-shin.L.001"].bbone_easein[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["thigh_ik_target.R"].hide[0]
ERROR (bke.anim_sys): C:\b\buildbot-worker-windows\windows_290\blender.git\source\blender\blenkernel\intern\anim_sys.c:2863 BKE_animsys_eval_driver: invalid driver - bones["VIS_thigh_ik_pole.R"].hide[0]

...
############################################################

I found this info: ... take care when switching out of Edit-Mode not to keep references to the edit bones or their head/tail vectors. from: https://docs.blender.org/api/current/info_gotcha.html#armature-mode-switching

I was, however, not able to resolve this by myself.

Any ideas?

Thanks! Nico

$\endgroup$
3
  • $\begingroup$ Hi and welcome! I don't think that's necessary, Epic is developing new tools to directly send it over. Have a look into: epicgames.github.io/BlenderTools $\endgroup$
    – brockmann
    Nov 10 '20 at 16:16
  • $\begingroup$ Well, I know these tools.Send2Unreal just sends anything you selected to UE. Rigify has a lot of bones I don't need there. UE2Rigify imports UE Mannequins into blender. What I want is to export my custom blender animations to UE without using Mannequin at all (I will have non-human rigs, too). $\endgroup$ Nov 11 '20 at 8:39
  • $\begingroup$ Hi Nico. I can't help you but I am interested in your script. Any plans to release it when it's done? A lot of people need a good workflow for exporting custom Rigify rigs to UE4. $\endgroup$
    – CGDive
    Nov 12 '20 at 23:44
0
$\begingroup$

I managed to resolve this with the help of blenderartists.

You have to remove constraints and drivers before deleting bones like so:

for bone in newRigObj.pose.bones:
    for constraint in bone.constraints:
        bone.constraints.remove(constraint)
            

for d in rigifyObj.animation_data.drivers:
    newRigObj.driver_remove(d.data_path, -1)

There were some more shenanigans but this is my result atm:

UE imported skeleton

Will now work on exporting animations.

Nico

$\endgroup$
1
  • $\begingroup$ Hi. Can you share the full updated script? $\endgroup$
    – CGDive
    Jul 2 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.