Sub topic 10
Extrapolation: What Happens Outside the Keys
Assume you can insert keyframes, play an animation, and open the Graph Editor. This chapter focuses on what Blender does before the first keyframe and after the last keyframe.
Extrapolation controls the outside of a curve
An F-curve defines a property value across time. Keyframes define the known part of that curve. Extrapolation defines the curve's behavior outside the first and last keyframes.
For example, suppose an object's X location is 0 at frame 1 and 4 at frame 24. Frames 1 through 24 are inside the keyed range. Frame 30 is outside it, so Blender must extrapolate the value.
The Graph Editor provides these main choices:
| Mode | Behavior outside the keyed range | Typical use |
|---|---|---|
| Constant | Holds the first or last value | A pose or property stays still |
| Linear | Continues the slope of the first or last segment | Continuous travel or rotation |
| Cycles modifier | Repeats the keyed range | Loops such as walking or blinking |
Constant and Linear are F-curve extrapolation modes. Cycles is an F-curve modifier that repeats the curve.
Set Constant or Linear extrapolation
- Select the animated object.
- Open the Graph Editor.
- Select the channel you want to change.
- Open the Channel menu.
- Choose Extrapolation Mode.
- Select Constant or Linear.
With Constant extrapolation, an object that reaches X = 4 at frame 24 remains at X = 4 on later frames. With Linear extrapolation, Blender continues the slope from the final segment. If the object moved from X = 0 to X = 4 over 23 frames, it continues moving at that rate.
Linear extrapolation uses the slope at each end. It does not simply continue the total distance between the first and last keys if the curve contains several segments.
import bpy
obj = bpy.context.object
if obj is None or obj.animation_data is None:
raise RuntimeError("Select an animated object first.")
action = obj.animation_data.action
fcurve = action.fcurves.find("location", index=0)
if fcurve is None:
raise RuntimeError("The object has no animated X location curve.")
fcurve.extrapolation = "LINEAR"Repeat motion with a Cycles modifier
To repeat a keyed motion, select the F-curve and choose Channel > Extrapolation Mode > Make Cyclic. Blender adds a Cycles modifier to the curve.
You can also add it with Python:
import bpy
obj = bpy.context.object
if obj is None or obj.animation_data is None:
raise RuntimeError("Select an animated object first.")
fcurve = obj.animation_data.action.fcurves.find("rotation_euler", index=2)
if fcurve is None:
raise RuntimeError("The object has no animated Z rotation curve.")
cycles = fcurve.modifiers.new(type="CYCLES")
cycles.mode_before = "REPEAT"
cycles.mode_after = "REPEAT"The modifier repeats the interval between the first and last keyframes. REPEAT starts the same motion again. Other cycle modes can repeat with offsets or reverse alternate cycles, depending on the result you need.
Diagnose unwanted motion
If an object moves after its final keyframe when it should stop, check whether the channel uses Linear extrapolation or has a Cycles modifier. Set the extrapolation to Constant and remove unwanted modifiers from the Modifiers panel.
Exercise
An object has keys at frames 1 and 20, but it keeps moving after frame 20. You want it to stop at its final value. What should you check and change?
Show answer
Select the relevant F-curve in the Graph Editor, remove an unwanted Cycles modifier if present, and set its extrapolation mode to Constant.