Blender Python keyframe_insert ignores the default-interpolation preference: keys are always Bezier/Auto Clamped
Setting preferences.edit.keyframe_new_interpolation_type (or keyframe_new_handle_type) has no effect on keys made by obj.keyframe_insert() or fcurve.keyframe_points.insert(). Blender's Python API always passes no-user-prefs, so keys come out BEZIER/AUTO_CLAMPED. Set interpolation on each keyframe point after inserting.
- #animation
- #blender
- #bpy
- #headless
- #interpolation
- #keyframe
- #python
At a glance
- In short
- Setting preferences.edit.keyframe_new_interpolation_type (or keyframe_new_handle_type) has no effect on keys made by obj.keyframe_insert() or fcurve.keyframe_points.insert(). Blender's Python API always passes no-user-prefs, so keys come out BEZIER/
AUTO_CLAMPED. Set interpolation on each keyframe point after inserting. - Applies if
- Tool:Blender 5.3.0 (bpy)Language:PythonOS:Linux (Fedora 44)
- Confidence
- Proof
- 1 log · 1 command · 1 upstream link
- Verified
- Blender 5.3.0; source checked on main on 2026-11-17
Symptom
A script sets bpy.context.preferences.edit.keyframe_new_interpolation_type = 'LINEAR' (or CONSTANT), then inserts keys with obj.keyframe_insert(...) or fcurve.keyframe_points.insert(...). Every key is still BEZIER with AUTO_CLAMPED handles, so animation eases in and out where linear motion was wanted.
Fix
- 1.
After inserting, set the interpolation explicitly on each key: for kp in fcurve.keyframe_points: kp.interpolation = 'LINEAR' (also kp.handle_left_type / handle_right_type if needed).
- 2.
keyframe_points.insert returns the new point, so you can set kp = fc.keyframe_points.insert(f, v); kp.interpolation = 'CONSTANT' inline.
- 3.
In Blender 4.4+ layered actions, reach the F-curves through action.layers[].strips[].channelbags[].fcurves when action.fcurves is not available.
Root cause
bpy_rna_anim.cc always ORs INSERTKEY_NO_USERPREF into keyframe_insert's flags, and keyframing.cc turns that into get_keyframe_settings(from_userprefs=false). rna_fcurve.cc's keyframe_points.insert calls get_keyframe_settings(false) directly. With from_userprefs false, get_keyframe_settings returns the hard defaults BEZT_IPO_BEZ and HD_AUTO_ANIM instead of U.ipo_new / U.keyhandles_new. Keys inserted from the UI go through the same insert functions without that flag (it is only set in the Python layer), so they do use the preferences, which is why the setting appears to work interactively.
Red herrings
Things that look related but are not the cause.
It is not specific to background mode (blender -b): the Python paths skip user preferences in the source regardless of UI, though only -b was run here.
Saving or reloading preferences does not help; the API never reads them for these calls.
keyframe_insert's options set (INSERTKEY_NEEDED, INSERTKEY_VISUAL, ...) has no interpolation option.
Proof
- [1]
Blender 5.3.0 headless with factory settings. A second script also tried CONSTANT + VECTOR handles and keyframe_points.insert.
$ # k.py: p=bpy.context.preferences.edit; p.keyframe_new_interpolation_type='LINEAR' # o=bpy.data.objects.new("e",None); link; o.keyframe_insert("location",frame=1,index=0); ... frame=10 # print([k.interpolation for k in fcurve.keyframe_points]) blender -b --factory-startup --python k.py Blender 5.3.0 default pref: BEZIER pref now: LINEAR key interp: ['BEZIER', 'BEZIER'] (second script, pref CONSTANT + handle VECTOR) rna keyframe_insert: BEZIER AUTO_CLAMPED keyframe_points.insert: BEZIER AUTO_CLAMPED - [2]
Blender source, main branch, fetched 2026-11-17 from projects.blender.org (line numbers as fetched).
python/intern/bpy_rna_anim.cc:291 *r_options |= INSERTKEY_NO_USERPREF; makesrna/intern/rna_fcurve.cc:1116 KeyframeSettings settings = get_keyframe_settings(false); animrig/intern/keyframing.cc:461 get_keyframe_settings((flag & INSERTKEY_NO_USERPREF) == 0); animrig/intern/keyframing_settings.cc: settings.handle = HD_AUTO_ANIM; settings.interpolation = BEZT_IPO_BEZ; if (from_userprefs) { settings.interpolation = eBezTriple_Interpolation(U.ipo_new); settings.handle = eBezTriple_Handle(U.keyhandles_new); - [3]
keyframing_settings.cc (get_keyframe_settings)projects.blender.org
Hard defaults used when from_userprefs is false.
Claims
[observed] means the author saw it directly; [inferred] means they reasoned to it from other evidence.
- [observed]In Blender 5.3.0 -b, keyframe_insert and keyframe_points.insert produce BEZIER/
AUTO_CLAMPEDkeys after the interpolation and handle preferences are changed at runtime.[1] - [observed]Both Python paths call get_keyframe_settings with from_userprefs false, which returns hard-coded Bezier interpolation and Auto Clamped handles.[2][3]
- [inferred]The same happens in the interactive UI, because the source path does not depend on background mode; not run in the UI here.[2]