Export actions(animations) to FBX and open in Unity I have a Problem with animating objects in Blender.

When I add the constraint "Follow_Path" to my objects and then bake animation, I have about seven additional Actions for one object.

The animation works very nice, but when I open the FBX format in Unity, I get all these actions and only one is the right one. For example Action.007

Mabye, I do something wrong with the selection?

Actions in Unity:



Here some Code:

def followPath():
    for object in scene.objects:
        scene.objects.active = object
        object.select = True
        bpy.ops.object.constraint_add(type='FOLLOW_PATH')
        # Settings
        forward_axis = getForwardAxis(path)#I get the path from another function
        up_axis = getUpAxis(path)
        constraint = bpy.data.objects[object.name].constraints["Follow Path"]
        constraint.target = bpy.data.objects[path.name]
        constraint.forward_axis = forward_axis
        constraint.up_axis = up_axis
        constraint.use_curve_follow = True
        # animate the path
        override = {'constraint': object.constraints["Follow Path"]}
        bpy.ops.constraint.followpath_path_animate(override, constraint='Follow Path')
        bakeAnimation()
        object.select = False

def bakeAnimation():
    bpy.ops.nla.bake(frame_start=1, frame_end=250, only_selected=True,
                 visual_keying=True, clear_constraints=True, clear_parents = True, bake_types={'OBJECT'})
I have the answer now:

The first problem is, that I don't clear the old actions when I start the script twice. Therefore, it appends the new actions to the old ones.
Now in Blender there are only the needed actions.

However, when I Export it to FBX and open it in Unity I have the same problem. 

You have to push the action down to a new strip:
Open the NLA-Editor and push that button next to your action.



For the export you have to select the following:



When you open your FBX in Unity there is only one action for each object.

How you do it in python:

#Add NLA-Strip
bpy.context.area.type = "NLA_EDITOR"
bpy.ops.nla.action_pushdown(channel_index = 1)#choose your index
#Export Settings 
bpy.ops.export_scene.fbx(filepath = yourfilepath,
                         use_selection=True,
                         bake_anim_use_all_bones = False,
                         bake_anim_use_nla_strips=True,
                         bake_anim_use_all_actions=False
                         )