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
    Commented Nov 10, 2020 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$ Commented Nov 11, 2020 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
    Commented Nov 12, 2020 at 23:44

1 Answer 1

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$
5
  • $\begingroup$ Hi. Can you share the full updated script? $\endgroup$
    – CGDive
    Commented Jul 2, 2021 at 7:51
  • $\begingroup$ Hi, very sorry to not answer your comment. I did actually not log into here for a very long time. I can see on your site that you've implemented your own version of Blender game rig tools. Do you still need the script (did you maybe find my github already? :))? $\endgroup$ Commented Nov 12, 2021 at 9:01
  • $\begingroup$ Thanks for replying. Yes, we created our own script for this. I don't think I found your github. Please share it :) $\endgroup$
    – CGDive
    Commented Nov 15, 2021 at 5:38
  • 1
    $\begingroup$ It's probably much more basic than what you did, but here it is: github.com/nibuettner/Blender/tree/master/nibuBlenderTools $\endgroup$ Commented Nov 18, 2021 at 9:06
  • $\begingroup$ Thanks for sharing! $\endgroup$
    – CGDive
    Commented Nov 19, 2021 at 1:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .