Sub topic 14
Constraint Order and Evaluation
This chapter assumes you can add bone constraints in Pose Mode, know the difference between owner and target space, and have set up a basic IK constraint. It explains how Blender evaluates a bone's constraint stack, why the order of constraints changes the result, and how to find order-related bugs.
How a Pose Bone Is Evaluated
A pose bone ends up with a final matrix in three steps:
- Blender computes the bone's transform from its parent, its rest pose, and the Location, Rotation, and Scale values you set (or keyed) in Pose Mode.
- Blender runs the bone's constraint stack from the top of the list to the bottom. Each constraint takes the matrix produced by the one above it and outputs a new matrix.
- The result becomes the bone's final pose. Child bones use it as their starting point.
Each constraint therefore works on the output of the previous one. It does not work on the original pose. The stack is a pipeline, and swapping two entries can change the result.
Why Order Matters
Two constraints on the same bone do different things when swapped. Consider a forearm bone that has both a Copy Rotation constraint and a Limit Rotation constraint.
| Order | What happens |
|---|---|
| Copy Rotation, then Limit Rotation | The bone copies the target's rotation, then the limit clamps it. The final rotation always stays inside the limit. |
| Limit Rotation, then Copy Rotation | The limit clamps the pose, then Copy Rotation overwrites it with the target's rotation. The limit has no visible effect. |
The general rule is that a constraint can only restrict or modify what the constraints above it produced. A limit constraint should usually be near the bottom, so it clamps the final result. Constraints that decide where a bone should point or move belong above it.
You change the order in the Bone Constraints tab by dragging the grip handle on a constraint's header. In Python, use bpy.ops.constraint.move_to_index with the constraint name and target index, or constraint.move_up and constraint.move_down. These operators need a pose bone context, so they are awkward in scripts. Often the simpler approach in a script is to add constraints in the order you want.
Influence in the Stack
Each constraint has an Influence value from 0 to 1. Blender blends between the matrix before the constraint and the matrix after it:
- At 1.0, the constraint's result replaces the incoming matrix.
- At 0.0, the incoming matrix passes through unchanged.
- At 0.5, the result is an interpolation between the two.
Influence is not applied to the original pose. It is applied to whatever the previous constraint produced. If you stack two Copy Rotation constraints at influence 0.5 each, the second one blends halfway between "after the first" and its own target. The bone ends up closer to the second target than the first.
IK Is Evaluated Differently
The IK constraint is the exception to the simple pipeline picture. When a bone has an IK constraint, Blender solves the whole chain (the bone and its parents, up to the chain length) together. It does not treat the bone in isolation.
Some consequences:
- The solver reads the pose of the chain's bones before the IK constraint runs, including the rotations you set by hand in FK.
- Constraints above the IK constraint on the same bone are applied first, and the IK solver then works from that result.
- Constraints on the other bones in the chain are evaluated as part of those bones' own stacks. They are not run inside the solver.
- Constraints placed after the IK constraint on the tip bone modify the solved result. This is the usual place for a Limit Rotation or a Copy Rotation that matches the hand to a control bone.
For example, a hand bone that should follow the rotation of a control bone while the arm is solved by IK is often set up as follows: the forearm has the IK constraint, and the hand bone has a Copy Rotation constraint targeting the hand control. They are on different bones, so there is no stack order to worry about between them. Dependencies between bones matter instead, as the next section describes.
Dependency Order Between Bones
Constraint order inside one bone is only part of the story. Blender also builds a dependency graph across the whole rig, and evaluates a bone only after the bones it depends on. A bone depends on:
- its parent
- the targets of its constraints
- the pole target, if it uses one
- any bone or property used by a driver on it
This is why a rig can work in one pose and break in another when there is a hidden loop. If bone A copies from bone B and bone B has a constraint targeting a child of A, Blender sees a dependency cycle. The result is a lag of one frame, or a bone that seems to trail behind. The viewport may show the bone in the previous frame's position.
Dependency cycles are found by reading the targets of each constraint and asking: "does this ever lead back to the owner or its children?" Two ways to fix a cycle:
- Retarget the constraint to a bone that is not downstream of the owner. A control bone that is not parented under the deformation chain is the usual solution.
- Remove the parent relationship that creates the loop and use a constraint such as Copy Transforms or Child Of to get the same effect.
Inspecting the Stack in Python
The constraint order is a plain list, so you can print it to check that a script produced the order you expected.
import bpy
rig = bpy.data.objects["ArmRig"]
bone = rig.pose.bones["forearm"]
for index, con in enumerate(bone.constraints):
target = getattr(con, "subtarget", "") or getattr(con, "target", None)
print(index, con.type, con.name, "influence=%.2f" % con.influence, "target=", target)The list is evaluated by index, starting at 0. A script that adds a Limit Rotation first and an IK constraint second gives a different stack from one that adds them in the opposite order, even though the code differs by one line.
You can also mute a constraint with con.mute = True (or the eye icon in the interface) to test one constraint's effect without removing it. Muting is a quick way to bisect a problem: mute everything, then enable constraints one at a time from the top until the pose goes wrong.
Owner and Target Space and Order
The Spaces chapter explained owner and target spaces. In the context of order, the key point is that "Local Space" for the owner is relative to the bone's parent and rest pose, but the matrix a constraint receives already includes the changes from the constraints above it. A Limit Rotation constraint in Local Space therefore clamps the rotation that the earlier constraints produced, not the rotation you typed into the Transform panel.
This is the reason a Limit Rotation constraint can seem to "fight" the values you enter. The panel shows your input, and the constraint stack shows the output. When the two differ, the bone is displayed with its constrained result, and the panel values stay as you typed them.
A Debugging Procedure
When a constrained bone does not behave, work through these steps:
- Open the Bone Constraints tab and read the stack top to bottom. Write down what each constraint should do to the pose.
- Mute all constraints, then unmute them in order. Note which one first produces a wrong result.
- Check that constraint's target, spaces, and influence.
- Check the order of that constraint relative to any Limit constraint, and move limits to the bottom.
- Check for a dependency cycle by following targets back to the owner or its children.
- If the problem is on an IK chain, also check the per-bone IK limits and locks, because they apply inside the solver and not in the stack.
Summary of Rules
- A stack runs top to bottom, and each constraint works on the previous output.
- Place Limit constraints below the constraints whose result they should restrict.
- Influence blends between the incoming matrix and the constraint's own result.
- IK solves the whole chain, and constraints after it on the tip bone act on the solved pose.
- Avoid targets that are children of the owner, which cause cycles and lag.
Exercise
A forearm bone has these constraints from top to bottom: Limit Rotation (Local, X from 0 to 150 degrees), then Copy Rotation targeting a control bone. The elbow bends backward past the limit when you rotate the control bone. Why does this happen, and what is the fix?
Show answer
Constraints run top to bottom, and Copy Rotation is below the limit. The limit clamps the pose first, then Copy Rotation overwrites the clamped result with the control bone's rotation, so the limit has no effect. Move Limit Rotation below Copy Rotation so it clamps the copied rotation.
Exercise
You add a hand control bone as a child of the forearm, and use it as the IK target for the forearm's IK constraint. The arm jitters and lags one frame behind when you move it. What is wrong, and how do you fix it?
Show answer
The target is a child of the bone it controls, which creates a dependency cycle. The target moves when the chain moves, so the solver chases a moving target and the result lags. Unparent the control bone, or parent it to something outside the chain such as the root or the rig object, so it does not depend on the chain it drives.