0
$\begingroup$

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:

actions

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'})
$\endgroup$
  • $\begingroup$ Can you post more of your script. Eg what is bakeAnimation(). Suggest using constraint = obj.constraints.new(type='FOLLOW_PATH') $\endgroup$ – batFINGER Aug 15 '17 at 5:44
  • $\begingroup$ Nothing changes with your suggestions. My main question is, why are there so many actions, while I only made one per object? $\endgroup$ – matt Aug 21 '17 at 6:54
  • $\begingroup$ did you check the action editor to see if they are there as well? You can try delete them from there. $\endgroup$ – SVAFnemesis Aug 21 '17 at 8:42
  • $\begingroup$ Thank you so much! That was not exactly the solution but I have it now. $\endgroup$ – matt Aug 21 '17 at 11:06
1
$\begingroup$

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:

enter image description here

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
                         )
$\endgroup$

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.