Changing Boids During Animation Crashes Blender

I have Python code that runs on each frame during animation, and changes the target which some boid particles are following. It’s fine during development (with Alt+P), but when I render, Blender crashes.

Here’s a simplified form of the code:

def change_boid_target(context):
    if (condition):
         # Get the boids' go-to-goal rule
         particle_system =['Emitter'].particle_systems[0];
         goal_rule = particle_system.settings.boids.states['State'].rules['Goal'];

         # Update the goal
         goal_rule.object =['Waypoint3'];

# Set change_boid_target() to run on each frame;

The crash happens on the line labelled “Update the goal”. Is there a workaround?

MANY thanks,

You may not be able to do that just yet with the current API. Meaning without crashing while rendering. But what you could do is instead of re-assigning the goal object simply assign the existing goal object’s location to the location of Waypoint3.

goal_rule.object.location =["Waypoint3"].location

Thanks, that solved it!