I made a script that creates hundreds of cubes using bpy.ops.object.duplicate(linked=True) that are given an initial velocity push upwards but the problem is that sometimes the cubes collide with one another in the beginning as shown in the orange circle area because they are too close and touching each other. This happens after physics simulation takes over after a few frames of animation when i set Animated (which is rigid_body.kinematic) to False via script. Adjusting this animation phase solely to make sure the cubes don't touch each other is a pain and will unlikely give me the desired projectile simulation result. So i need a way to temporarily disable collision detection. I will turn on collision detection later in the timeline. So i need something like this:

o.rigid_body.collision_detection = False
o.keyframe_insert(data_path = "collision_detection?", frame = frame_off_collision)
o.rigid_body.collision_detection = True
o.keyframe_insert(data_path = "collision_detection?", frame = frame_on_collision)

enter image description here

I have also tried the answer of @Ratt's script and i can see that collision is disabled (closed eye icon) but the cubes still collide

enter image description here


1 Answer 1


If I understand correctly you already have the collision setting setup as desired for the end of the animation and you only need to have them disabled at the beginning.

as such something like the following should work:

import bpy

obj = bpy.context.object

d_path = "use"
frame_off_collision = 1
frame_on_collision = 10

obj.collision.use = False
obj.collision.keyframe_insert(data_path = d_path, frame = frame_off_collision)
obj.collision.use = True
obj.collision.keyframe_insert(data_path = d_path, frame = frame_on_collision)

Keep in mind that you likely want to have an offset for the frame on and off based on when the initial cubes are spawned but You didn't specify if they are spawned based on a particle system or some other method.

  • $\begingroup$ thank you for your response. i updated my post, i'm creating them via duplicate function. i tested your script (turned off collision at frame 1) without the last 2 lines but they still collide even though i didn't turn the collision back on. Are you sure the data_path is really only "use"? that's kinda odd. $\endgroup$ May 24, 2022 at 5:13
  • 1
    $\begingroup$ It appears as though bpy.context.object.rigid_body.kinematic is tied to the mesh datablock for the simulation instead of the object datablock as such trying to set the values on linked mesh data will not work as expected but instead set the value for all items of the linked mesh. With regards to the data_path the full data_path would reference the 'bpy.data.objects['object_name'].collision.use' but in the command the keyframe_insert is already at 'bpy.data.objects['object_name'].collision` and only needs the relative path from there. $\endgroup$
    – Ratt
    May 24, 2022 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .