Sub topic 3
What a keyframe is
This chapter assumes you can move around the 3D Viewport, select and transform objects, and find fields in the Properties editor. It also assumes you can change an editor's type and resize areas. You do not need to know the Timeline or the Dope Sheet yet. They come in later chapters.
The working model
A keyframe is a stored value of one property at one frame. Blender does not store the motion between keyframes. It stores only the values you pin down, and it calculates every frame in between.
Suppose you key an object's Z location as 0 at frame 1 and 2 at frame 24. Blender stores two numbers, each tied to a frame. When you view frame 12, Blender computes a value between 0 and 2 and moves the object there. This calculation is called interpolation.
Each keyframe belongs to one property channel. An object's Location has three channels: X, Y and Z. Keying Location normally creates a keyframe on each of the three. Rotation, Scale and other properties have their own channels.
A keyframe therefore has three parts:
- The property it controls, such as Location Z.
- The frame it sits on, such as 24.
- The value at that frame, such as 2.0.
Blender also stores how to interpolate toward the next keyframe. That setting belongs to the keyframe, and a later chapter covers it.
What happens before, between and after keys
Blender evaluates an animated property differently depending on where the current frame falls.
| Current frame | Value Blender uses |
|---|---|
| Before the first keyframe | The value of the first keyframe |
| Exactly on a keyframe | The stored value |
| Between two keyframes | An interpolated value |
| After the last keyframe | The value of the last keyframe |
With the default extrapolation, the value is held constant outside the keyed range. The object does not keep drifting after the final key. The frame range of the scene is separate from the keyed range. If you key frames 1 and 24 but the scene runs to frame 48, the object sits still from frame 24 to 48.
The default interpolation between keys is Bézier, which eases in and out. Motion starts slowly, speeds up, and slows down again near the next key. If you want constant speed, you change the interpolation to Linear, as shown at the end of this chapter.
Animated values override manual edits
An animated property is controlled by its keyframes. Every time the frame changes, Blender reevaluates the property from its curve and overwrites whatever value is currently there.
This causes the most common beginner error. You move an animated object in the 3D Viewport at some frame without keying it. The object moves, and it looks as if the edit worked. Then you change the frame, and the object snaps back to the keyed value. Your edit was never stored.
The fix is to insert a keyframe after you edit, which updates the stored value. The next chapter covers inserting, updating and deleting keys in detail.
Blender shows the state of a property with color in the interface:
- Gray means the property is not animated.
- Yellow means the current frame has a keyframe on this property.
- Green means the property is animated, but the current frame has no keyframe.
- Orange means the property is animated and you changed its value without keying it. This is the unsaved-edit state described above.
The Properties editor and the 3D Viewport's sidebar use these colors on value fields. Watch for orange. It tells you a value will be lost when the frame changes.
Keyframes and frames are separate ideas
A frame is a position in time. A keyframe is a stored value at a frame. Every frame in the scene exists whether or not it holds a keyframe. Most frames hold none, and that is normal. A short move often needs only two keyframes, and Blender fills in the rest.
Because keyframes store values and not motion, you can change the timing without touching the values. Moving the second key from frame 24 to frame 48 makes the same rise happen more slowly. Changing the value at frame 24 from 2.0 to 5.0 makes the rise taller but keeps the timing. These two edits are the basis of the later chapters on editing and retiming.
A worked example in Python
The scripted version shows exactly what a keyframe stores. Run this with an object selected and active. Open the Scripting workspace, paste the code into the Text Editor, and press Run Script.
import bpy
scene = bpy.context.scene
scene.frame_start = 1
scene.frame_end = 48
obj = bpy.context.active_object
obj.location = (0.0, 0.0, 0.0)
obj.keyframe_insert(data_path="location", frame=1)
obj.location = (0.0, 0.0, 2.0)
obj.keyframe_insert(data_path="location", frame=24)The script does the following:
- It sets the scene's frame range to 1 through 48.
- It sets the object's location to the origin and calls
keyframe_insertwithdata_path="location"andframe=1. That stores a key on all three location channels at frame 1. - It sets the location to Z = 2 and stores a second key at frame 24.
The object rises two units over 23 frames. The frame argument decides where the key is stored. It does not change the current frame. After the script runs, the object sits at Z = 2 because that was the last value assigned. Moving the playhead to frame 1 returns it to the origin.
You can set the interpolation of the stored keys. This script is the scripted equivalent of selecting all keys in the Dope Sheet and choosing Linear from the Interpolation Mode menu (T).
import bpy
obj = bpy.context.active_object
action = obj.animation_data.action
for fcurve in action.fcurves:
for keyframe in fcurve.keyframe_points:
keyframe.interpolation = 'LINEAR'The code reads the object's action, which holds the animation curves, and goes through each curve's keyframe points. This F-curve access works in Blender 2.8 through 4.x. Newer versions with layered actions may access F-curves differently, so check the Python API documentation for your version.
To evaluate the animation at a chosen frame, set the current frame from a script:
import bpy
scene = bpy.context.scene
scene.frame_set(12)
print("Current frame:", scene.frame_current)Calling frame_set(12) does the same as clicking frame 12 in the Timeline. Blender reevaluates animated properties at that frame, so the object appears at the interpolated position.
Common errors
- The object snaps back after a move. You edited an animated property without keying it. Insert a keyframe after the edit.
obj.animation_dataisNone. The object has no animation yet. Insert at least one keyframe before readinganimation_data.action.- Animation stops partway through playback. The last keyframe is earlier than the end of the frame range. The value holds after the last key. This is expected behavior.
- A key appears on the wrong frame in a script.
keyframe_insertuses the current frame if you omitframe. Passframe=explicitly.
Exercise
An object has keyframes on Location Z at frame 1 (value 0) and frame 24 (value 2). The scene frame range is 1 to 48. What is the object's Z location at frame 40, and why? What would you see if you moved the object to Z = 5 at frame 40 without keying it and then changed the frame to 41?
Show answer
At frame 40 the Z location is 2. Frame 40 is after the last keyframe, so Blender holds the value of that last key. If you move the object to Z = 5 without keying, the Z field turns orange because the value differs from the animation. When you change the frame to 41, Blender reevaluates the curve, discards the unkeyed edit and returns Z to 2.
Exercise
A keyframe stores three pieces of information about a property. Name them, and explain why a short move often needs only two keyframes.
Show answer
A keyframe stores the property it controls, the frame it sits on, and the value at that frame. Blender interpolates every frame between two keys, so a move from one value to another only needs a key at the start and at the end.