Page MenuHome

bpy.ops.logic.controller_add() is too eager in making name unique
Closed, ResolvedPublic


System Information
Ubuntu 14.10, GeForce 460.

Blender Version
Broken: 2.72b & 2f637004d57b4220e483dc60f72edc86b88d3102

Short description of error
bpy.ops.logic.controller_add(type='PYTHON', name='Startup') will create a controller that is named Startup1 when there is already another logic brick with the name Sensor. However, in the GUI itself, it is perfectly possible to have both a sensor and controller with the same name.

Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps

  1. Open the attached Blend file
  2. Run the script in the bottom panel
  3. Inspect the names of the logic bricks

*Expected behaviour*: both logic bricks are named Startup
*Observed behaviour*: the controller is named Startup1

You can rename the controller to Startup, and see that Blender allows this just fine.

Event Timeline

I just figured out this doesn't just happen with logic bricks within one object. It also occurs when adding bricks to multiple objects. For example, when there are two cubes Cube and Cube.001, and this code is executed:

import bpy

bpy.ops.logic.sensor_add(type='ALWAYS', name='SENS-Startup', object='Cube')
bpy.ops.logic.controller_add(type='PYTHON', name='CTRL-Startup', object='Cube')

bpy.ops.logic.sensor_add(type='ALWAYS', name='SENS-Startup', object='Cube.001')
bpy.ops.logic.controller_add(type='PYTHON', name='CTRL-Startup', object='Cube.001')

Afterward, Cube has SENS-Startup, and Cube.001 has SENS-Startup1. Same for the controllers.

This makes it cumbersome to programmatically create new controllers, and then directly access them, as the numeric suffix needs to be found and eliminated.