Reply To: Can you export NLA strips from one track that pull from other tracks additively?

Forum Archive Can you export NLA strips from one track that pull from other tracks additively? Reply To: Can you export NLA strips from one track that pull from other tracks additively?

#69953
ngon
Participant

    Thank you for your reply.  I actually just spent the day finishing up my new workflow which involved a bit of scripting…

    Sharing the grip portion of the animation across different animations was scrapped.  It would be a nice feature but at the end of the day its not a big deal to just go an update every animation in that way if I need to.

    I was pretty keen on having a different animation file for each animation since unreal engine’s importer kinda sucks and having multiple animations in a single fbx can cause problems that can only be resolved by deleting everything and starting over.

    What I ended up with is a system where I’m using one scene for each animation.  Each scene has its own library override of my skeleton rig from another .blend file.  This is actually pretty easy to use because if I just make a new scene with the “Full Copy” option it does that all for me automatically.  

    The big problem I had with this method is that each library override object had to have a different name.  So the second animation would be rig.001 and the third would be rig.002.  Apparently Unreal’s importer freaks out if the rig is not named “rig” so I had to go and write a python script that essentially detects all the rigs that I actually want to export across all my scenes and change their name to ‘rig’, exports them, and changes  their name back to a unique identifier after the export.  It’s not quite finished yet since the save directory and file name are hard coded but, if you’re curious.

    import bpy
    
    
    print('\n\n\nN_GON: RUNNING UNREAL BATCH ANIMATION EXPORT SCRIPT!')
    
    objects = bpy.data.objects
    exportList = []
    print(objects[0])
    
    #Populate exportList with all objects of type armature that's name begins with "rig"
    for obj in objects:
        if (obj.type == "ARMATURE"):
            if obj.name.lower().startswith("rig"):
                #check if the rig is part of a scene.  If its not, that's because its the skeleton we're linked to which we dont export
                #alternatively, it could be a lingering object that is no longer part of any scene which we also dont export...
                if (len(obj.users_scene) > 0):
                    exportList.append(obj)
                
    #Ensure there is only one armature named rig[...] per scene
    sceneList = []
    for export in exportList:
        sceneList.append(export.users_scene)
    
    if not (len(set(sceneList)) == len(sceneList)):
        raise Exception("Multiple Armatures with prefix 'rig' detected per scene.  Nothing was exported")
        
    #code from forums to store export parameters from preset to 'op'
    presetDirectory = bpy.utils.preset_paths('operator/export_scene.fbx/')
    presetPath = presetDirectory[0] + 'UE4_Animation.py'
    
    file = open(presetPath, 'r')
    class emptyclass():
        __slots__ = ('__dict__',)
    op = emptyclass()
    
    for line in file.readlines()[3::]:
        exec(line, globals(), locals())
    
    print('N_GON: EXPORTING THE FOLLOWING RIG OBJECTS...')
    for export in exportList:
        print(export.name)
    
    #export!
    activeScene = bpy.context.window.scene
    
    for export in exportList:
        bpy.context.window.scene = export.users_scene[0]
        export.name = "rig"
        
        op.filepath = 'C:\\Users\\Desktop\\Desktop\\New Folder\\' + 'test' + '_' + export.users_scene[0].name + '.fbx'
        kwargs = op.__dict__
        
        bpy.ops.export_scene.fbx(**kwargs)
        
        export.name = "rig_" + export.users_scene[0].name
        export.data.name = "rig_" + export.users_scene[0].name
        
    bpy.context.window.scene = activeScene
        
    
    

    Anyways, long story short I think I’m fairly happy with the workflow I managed to set up.  Sadly it feels like Blender’s animation featureset was not designed for gamedev at all but…I guess that’s just how it is.  I may need to modify my workflow a bit when I have to have certain weapons that have their own skeletal mesh (like a bow that might bend as the string is pulled back), but think I’m good for now.

    I still have no idea what that dotted orange line was on my NLA strip. I have not seen it come back in any of my recent files/tests though.