Application Handlers (

This module contains callback lists

Basic Handler Example

This script shows the most simple example of adding a handler.

import bpy

def my_handler(scene):
    print("Frame Change", scene.frame_current)

Persistent Handler Example

By default handlers are freed when loading new files, in some cases you may want the handler stay running across multiple files (when the handler is part of an add-on for example).

For this the decorator needs to be used.

import bpy
from import persistent

def load_handler(dummy):
    print("Load Handler:",

Note on Altering Data

Altering data from handlers should be done carefully. While rendering the frame_change_pre and frame_change_post handlers are called from one thread and the viewport updates from a different thread. If the handler changes data that is accessed by the viewport, this can cause a crash of Blender. In such cases, lock the interface (Render → Lock Interface or bpy.types.RenderSettings.use_lock_interface) before starting a render.

Below is an example of a mesh that is altered from a handler:

def frame_change_pre(scene):
    # A triangle that shifts in the z direction
    zshift = scene.frame_current * 0.1
    vertices = [(-1, -1, zshift), (1, -1, zshift), (0, 1, zshift)]
    triangles = [(0, 1, 2)]

    object =["The Object"], [], triangles)

on depsgraph update (post)

on depsgraph update (pre)

Called after frame change for playback and rendering, after the data has been evaluated for the new frame.

Called after frame change for playback and rendering, before any data is evaluated for the new frame. This makes it possible to change data and relations (for example swap an object to another mesh) for the new frame. Note that this handler is not to be used as ‘before the frame changes’ event. The dependency graph is not available in this handler, as data and relations may have been altered and the dependency graph has not yet been updated for that.

on loading factory preferences (after)

on loading factory startup (after)

on loading a new blend file (after)

on loading a new blend file (before)

on loading a redo step (after)

on loading a redo step (before)

on canceling a render job

on completion of render job

on initialization of a render job

on render (after)

on render (before)

on printing render statistics

on writing a render frame (directly after the frame is written)

on saving a blend file (after)

on saving a blend file (before)

on loading an undo step (after)

on loading an undo step (before)

on ending the versioning code

on starting an xr session (before)

Function decorator for callback functions not to be removed when loading new files