Canonical URL: https://sunfield.dev/blog/blender-4-5-lts-headless-bpy-gotchas
Published: 2026-11-17 | Category: Blender Engineering | Reading time: 5 min
Hero Render: https://sunfield.dev/blog/optics-rangefinder-og.jpg

# Seven Blender 4.5 headless bpy gotchas we keep hitting

I submit that every team automating **Blender 4.5.0 LTS** headlessly runs into the same seven `bpy` failures within their first week. Coding agents and old StackExchange answers still emit Blender 3.6 code, and half of these breaks do not raise an exception – they quietly write wrong pixels.

Here are all seven, and the minimal fixes we run in our worker.

## 1. `BLENDER_EEVEE` vs `BLENDER_EEVEE_NEXT`

Blender 4.2 through 4.5 renamed the EEVEE engine enum to `'BLENDER_EEVEE_NEXT'`, while 3.x and 5.x call it `'BLENDER_EEVEE'`. Hardcoding either string guarantees breakage when you upgrade. Query `bl_rna` once instead:

```python
import bpy

def pick_eevee_engine() -> str:
    items = [e.identifier for e in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
    for candidate in ("BLENDER_EEVEE_NEXT", "BLENDER_EEVEE"):
        if candidate in items:
            return candidate
    return "CYCLES"
```

## 2. `Principled BSDF` socket renames

Blender 4.0 renamed five inputs that appear in almost every procedural material script. Indexing `bsdf.inputs["Specular"]` directly throws `KeyError`. Guard every socket assignment with `if name in bsdf.inputs:` or map them explicitly:

| Blender 3.x | Blender 4.5 LTS |
| :--- | :--- |
| `Specular` | `Specular IOR Level` |
| `Clearcoat` | `Coat Weight` |
| `Transmission` | `Transmission Weight` |
| `Subsurface` | `Subsurface Weight` |
| `Emission` | `Emission Color` and `Emission Strength` |

## 3. `primitive_*_add(rotation=...)` silently ignored in background mode

Without an active 3D viewport context, `bpy.ops.mesh.primitive_cube_add` and `primitive_cylinder_add` can ignore the `rotation=` keyword argument and leave the object at `(0, 0, 0)`. You get no warning and no exception. Set `obj.rotation_euler` directly after creation:

```python
bpy.ops.mesh.primitive_cylinder_add(radius=0.05, depth=0.2, location=(0.0, 0.0, 0.1))
obj = bpy.context.active_object
obj.rotation_euler = (1.5708, 0.0, 0.0)
```

## 4. `BVHTree.FromObject()` operates in local space

This one looks like a bug until you read the C source carefully. `BVHTree.FromObject(obj, depsgraph)` builds the tree in **object-local coordinates**, ignoring `obj.matrix_world`. Put two cubes 5 metres apart via `obj.location` and `bvh_a.overlap(bvh_b)` still reports a collision at the origin. Always transform evaluated vertices into world space first:

```python
from mathutils.bvhtree import BVHTree

def world_bvh(obj, depsgraph):
    eval_obj = obj.evaluated_get(depsgraph)
    mesh = eval_obj.to_mesh()
    try:
        verts = [eval_obj.matrix_world @ v.co for v in mesh.vertices]
        polys = [tuple(p.vertices) for p in mesh.polygons]
        return BVHTree.FromPolygons(verts, polys)
    finally:
        eval_obj.to_mesh_clear()
```

## 5. `BLENDER_EEVEE_NEXT` ignores `view_layer.material_override`

In Cycles, setting `view_layer.material_override` renders a clean clay or wireframe pass. In EEVEE Next `4.5.0`, it silently renders the normal RGB scene. If you want an EEVEE wireframe or segmentation override, swap `obj.data.materials` per mesh inside a `try/finally` block – and **save and restore `[p.material_index for p in obj.data.polygons]`**. Clearing `obj.data.materials` without restoring polygon indices permanently flattens multi-material meshes to slot `0`.

## 6. `AgX` shifts flat segmentation RGB IDs

If you encode object IDs as flat emission colours (eg, `[87, 36, 242]`) and render while `AgX` is active, tone-mapping shifts that colour to `[152, 128, 208]`. Your mask parser then sees zero matching pixels. Switch `scene.view_settings.view_transform = "Raw"` and `look = "None"` for the segmentation pass, then restore `AgX`.

## 7. Compositor `Normal` output clips `[-1, 0]` to black in PNG

Wiring `Render Layers → Normal` straight into a PNG `File Output` node throws away every negative normal component, because PNG cannot store signed floats. Remap `[-1, 1] → [0, 1]` per channel using `CompositorNodeSeparateColor`, three clamped `CompositorNodeMapRange` nodes, and `CompositorNodeCombineColor`.

Note that if you only ever render interactive beauty frames in the desktop GUI, items 3 through 7 probably never bite you. The moment you run Blender as a headless batch compiler for agents or CV datasets, all five will.
---

Sign in or connect Remote MCP (`https://sunfield.dev/mcp`) at https://sunfield.dev/login. All posts: https://sunfield.dev/blog
