Sub topic 15
Drivers: F-Curves Driven by Other Values
Drivers connect one property to another value. A normal F-curve maps the current frame to a property value. A driver F-curve evaluates an expression using variables, such as another object's location, a custom property, or the scene frame.
Assume you know how to insert keyframes, change editor types, and work with object properties.
How a driver works
A driver has three main parts:
- The driven property is the value Blender changes, such as an object's Z rotation.
- A variable reads an input value, such as a custom property named
turn. - An expression converts the input into the driven value.
For example, the expression turn * 0.0174533 converts degrees to radians. Blender stores Euler rotation values in radians.
| Part | Example | Purpose |
|---|---|---|
| Driven property | Cube Z rotation | Value controlled by the driver |
| Variable | `turn` | Reads an input value |
| Expression | `turn * 0.0174533` | Calculates the output |
A driver replaces direct keyframe evaluation for the driven component. You generally cannot animate that same component with ordinary keyframes until you remove the driver.
Creating a driver in the interface
To create a simple driver:
- Select an object and locate a property, such as Rotation Z.
- Right-click the property and choose Add Driver.
- Open the Graph Editor and change its mode to Drivers.
- Select the driver channel. Use the Drivers panel to inspect its variables and expression.
- Add a variable, choose its target object, and select the property or transform channel it should read.
- Enter an expression that uses the variable name.
You can also right-click a property and choose Copy Data Path. A data path identifies a property inside Blender's data model. It helps when setting up a Single Property driver variable.
A complete Python example
This script adds a custom property named turn to the active object and drives its Z rotation. Run it in Blender's Scripting workspace with an object selected.
import bpy
obj = bpy.context.object
if obj is None:
raise RuntimeError("Select an object before running this script.")
# The input value is stored on the object.
obj["turn"] = 0.0
# Add a driver to the Z component of rotation_euler.
fcurve = obj.driver_add("rotation_euler", 2)
driver = fcurve.driver
driver.type = "SCRIPTED"
# Read the custom property from the same object.
variable = driver.variables.new()
variable.name = "turn"
variable.type = "SINGLE_PROP"
target = variable.targets[0]
target.id = obj
target.data_path = '["turn"]'
# Convert degrees to Blender's radians.
driver.expression = "turn * 0.017453292519943295"
# Change the input. The cube should rotate to 90 degrees.
obj["turn"] = 90.0
bpy.context.view_layer.update()
print("Z rotation in radians:", obj.rotation_euler.z)The variable name must match the name used in the expression. If the variable is named turn but the expression uses angle, Blender cannot evaluate it correctly.
Common errors and debugging
A driver can fail silently or display an error icon when its input is missing. Check these causes:
- The target object was deleted or renamed.
- The data path points to a property that no longer exists.
- The expression uses an undefined variable.
- A custom property is stored on a different object than the target.
- The expression produces a value in the wrong unit, such as degrees instead of radians.
- The driver is muted in the Graph Editor or through the channel controls.
Use the Drivers panel to inspect the variable target and expression. Test the source property separately before changing the expression. Keep expressions short. Put complicated calculations in a custom property, a scripted setup, or another controlled input rather than hiding them in one long expression.
Exercise
A driver's variable reads a custom property named "speed", but the expression says "rate * 2". What should you change?
Show answer
Change the expression to "speed * 2", or rename the variable to "rate". The variable name and expression must match.