Sub topic 2
What an F-curve is: one property, one curve over time
An F-curve is the object Blender uses to store animation for one value. This chapter explains what an F-curve holds, how it is addressed, and how it is evaluated at a given frame. Later chapters cover editing it in the Graph Editor.
It assumes you can navigate the 3D Viewport, insert keyframes with I or in the Timeline and Dope Sheet, and use playback controls. It also assumes you know that location, rotation and scale are properties of an object.
One property, one curve
An F-curve (short for function curve) maps time to a single number. You give it a frame, and it returns the value of one property at that frame.
This has a consequence that surprises many people. A vector property such as location holds three numbers, X, Y and Z. When you animate it, Blender creates three separate F-curves, one for each component. Each curve has its own keyframes, interpolation and handles. Pressing I over the Location field only inserts a key on each of those three curves at the same time.
| Property | Number of values | F-curves created |
|---|---|---|
| Object location | 3 | 3 |
| Object rotation (Euler) | 3 | 3 |
| Object rotation (quaternion) | 4 | 4 |
| Object scale | 3 | 3 |
| Light energy | 1 | 1 |
| Material base color (RGBA) | 4 | 4 |
If you key only the X component, only one curve exists. You can add Y later without disturbing X.
Where F-curves live
An F-curve is not stored on the object itself. The chain of ownership has three levels.
- The object has an
animation_datablock. It is created the first time you insert a keyframe. - The animation data points to an action, a named container of animation. Several objects can share one action, and one object can switch between actions.
- The action holds a list of F-curves. Each F-curve holds its own keyframe points.
The previous chapter in the plan covered actions in more detail. Here the important point is that the Graph Editor shows the F-curves of the action, not of the object. If you assign a different action, you see different curves.
Data path and array index
Blender needs a way to say which property a curve controls. It uses two fields, which together identify the curve inside its action.
- The data path is a string that names the property, starting from the animated data block. Examples are
location,rotation_eulerandscale. - The array index is the position of the component within that property. For a vector, 0 is X, 1 is Y and 2 is Z. For a single value such as a light's energy, the index is 0.
So the curve for X location has the data path location and array index 0. The curve for Z scale has the data path scale and index 2.
Paths can reach deeper into the data, and the same two-field scheme still applies.
| Animated thing | Data path | Index |
|---|---|---|
| Y location of an object | `location` | 1 |
| X rotation of an object | `rotation_euler` | 0 |
| A custom property named `speed` | `["speed"]` | 0 |
| Z location of a pose bone named `arm` | `pose.bones["arm"].location` | 2 |
| Value of a shape key named `Smile` | `key_blocks["Smile"].value` | 0 |
Because the path is a string, an F-curve can become orphaned. If you rename the bone arm to upper_arm, the old path no longer resolves. The Graph Editor then marks the channel with a red underline, and the curve has no effect. This is the most common cause of "my animation stopped working" after renaming things.
Keyframe points
An F-curve is made of keyframe points. Each point has these parts:
- A frame (the horizontal position) and a value (the vertical position). Together they are the
cocoordinate. - An interpolation mode, which controls the shape of the curve between this point and the next one.
- Two Bezier handles, left and right, each with a handle type.
The interpolation setting belongs to the point at the start of a segment. If key A is Constant and key B is Bezier, the segment from A to B is constant, and the segment from B to the next key is Bezier. Later chapters cover interpolation and handles in detail.
Evaluating a curve
When the playhead sits on a frame, Blender evaluates every F-curve at that frame and writes the result into its property. The process is:
- Find the two keyframe points on either side of the current frame.
- Compute the value between them using the first point's interpolation mode.
- Apply any F-curve modifiers, covered in a later chapter.
- Write the final number to the property.
Two details follow from this.
First, evaluation is a function of the frame number only. The curve does not remember the previous frame, so jumping straight to frame 200 gives the same result as playing up to it.
Second, the animation system overwrites the property on every frame change. If you move an animated object by hand and then change frames, it snaps back to the curve value. To keep your change, insert a keyframe, or edit the curve.
Outside the first and last key, the curve has no neighbours to interpolate between. By default it holds the end value flat. This behaviour is called extrapolation, and it gets its own chapter.
Reading F-curves from Python
The Python API exposes the same structure. This script creates two keyframes and then finds the X location curve by data path and index. It needs an active object in the scene, such as the default cube.
import bpy
obj = bpy.context.object
obj.location = (0.0, 0.0, 0.0)
obj.keyframe_insert(data_path="location", frame=1)
obj.location = (4.0, 0.0, 0.0)
obj.keyframe_insert(data_path="location", frame=24)
# The X location curve has data path "location" and array index 0.
fcurve = obj.animation_data.action.fcurves.find("location", index=0)
print(fcurve.data_path, fcurve.array_index, len(fcurve.keyframe_points))The output is location 0 2: the curve's path, its index, and the number of keyframe points. The script also created curves for indices 1 and 2, because keyframe_insert keys all three components when you give it location without an index.
You can also ask a curve for its value at any frame with evaluate. This script lists every curve in the action and samples the one you looked up.
import bpy
obj = bpy.context.object
action = obj.animation_data.action
for fc in action.fcurves:
print(fc.data_path, fc.array_index)
fcurve = action.fcurves.find("location", index=0)
for frame in (1, 12, 24, 40):
print(frame, fcurve.evaluate(frame))With the keys from the first script, frame 1 gives 0.0 and frame 24 gives 4.0. Frame 12 gives a value between them that depends on the interpolation, and frame 40 gives 4.0 because the end value is held.
Common errors
- Looking for one curve per object. An object with animated location and rotation has at least six curves, so expect that many channels.
- Wrong array index. If
findreturnsNone, the path or index does not match any curve. Print the paths in the action first, as the second script does. - Reading
animation_databefore any key exists. It isNoneuntil the first keyframe is inserted, so the attribute access raises an error. - Broken paths after renaming. Renaming a bone, shape key or modifier leaves the old path in the curve, which then does nothing.
- Expecting a manual edit to persist. The curve value replaces your edit on the next frame change.
Exercise
An object has its X and Z location keyed, but Y was never keyed. How many F-curves does the action contain for location, and what are their data paths and indices?
Show answer
Two F-curves. Both have the data path "location". One has array index 0 (X) and the other has array index 2 (Z). No curve exists for index 1 because Y was never keyed.
Exercise
You rename a bone from "arm" to "upper_arm" after animating it. The bone stops moving, and the channel shows a red underline in the Graph Editor. Why, and what is the cause in terms of the F-curve's fields?
Show answer
The F-curve stores the data path as the string pose.bones["arm"].location. After the rename, no bone called "arm" exists, so the path no longer resolves and the curve cannot write its value to anything. Fixing the data path to use "upper_arm" restores the animation.