Drivers can have multiple variables with same name #94116

Closed
opened 2021-12-15 16:24:23 +01:00 by Bastien Montagne · 10 comments

Currently, drivers can get several variables with the same exact name.

Besides being useless and confusing (typically, driver will only use the first one then), this is also a problem for library overrides, since there are several data (driver variables) with the same exact RNA path.

You can check e.g. lib/char/butterfly/butterfly.blend from sprite production files, GEO-butterfly_antennas object's drivers, burnt one has three burnt variables.

butterfly.blend


LibOverride issue can be fixed by forbidding usage of names for the driver variables collection (only indices would be used then). However this has serious downsides, first one being that if a driver has several valid variables and they get re-arranged, the overrides will need to be resynced.

And in general I don't think such confusing useless situation should be allowed at all.

So think there should be a mechanism (maybe as part of driver_variable_name_validate ?) that should ensure unique names?

NOTE: found while investigating mysterious 'always need to resync overrides' cases from #94059.

Currently, drivers can get several variables with the same exact name. Besides being useless and confusing (typically, driver will only use the first one then), this is also a problem for library overrides, since there are several data (driver variables) with the same exact RNA path. You can check e.g. `lib/char/butterfly/butterfly.blend` from sprite production files, `GEO-butterfly_antennas` object's drivers, `burnt` one has three `burnt` variables. [butterfly.blend](https://archive.blender.org/developer/F12748523/butterfly.blend) ---------------------------------- LibOverride issue can be fixed by forbidding usage of names for the driver variables collection (only indices would be used then). However this has serious downsides, first one being that if a driver has several valid variables and they get re-arranged, the overrides will need to be resynced. And in general I don't think such confusing useless situation should be allowed at all. So think there should be a mechanism (maybe as part of `driver_variable_name_validate` ?) that should ensure unique names? NOTE: found while investigating mysterious 'always need to resync overrides' cases from #94059.
Author
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Owner

Added subscribers: @mont29, @dr.sybren

Added subscribers: @mont29, @dr.sybren

Added subscriber: @dfelinto

Added subscriber: @dfelinto

For the records, in my tests here the drivers use the last variable, not the first one.

For the records, in my tests here the drivers use the last variable, not the first one.
Author
Owner

Added subscribers: @SimonThommes, @eyecandy

Added subscribers: @SimonThommes, @eyecandy
Author
Owner

@eyecandy @SimonThommes Also thing you need to know for now imho.

For the time being, this simple script allows to clean things up:

for _name in dir(bpy.data):

iterable = getattr(bpy.data, _name)
if not isinstance(iterable, bpy.data.objects.class):
continue
for id in iterable:
if not getattr(id, "animation_data", None):
continue
for driver in id.animation_data.drivers:
variable_names = set()
for variable in driver.driver.variables:
if variable.name in variable_names:
print("ERROR! ID driver '%s.%s' has several variables named '%s', removing the extra ones." % (id.name, driver.data_path, variable.name))
driver.driver.variables.remove(variable)
else:
variable_names.add(variable.name)

@eyecandy @SimonThommes Also thing you need to know for now imho. For the time being, this simple script allows to clean things up: ```lang=python for _name in dir(bpy.data): ``` iterable = getattr(bpy.data, _name) if not isinstance(iterable, bpy.data.objects.__class__): continue for id in iterable: if not getattr(id, "animation_data", None): continue for driver in id.animation_data.drivers: variable_names = set() for variable in driver.driver.variables: if variable.name in variable_names: print("ERROR! ID driver '%s.%s' has several variables named '%s', removing the extra ones." % (id.name, driver.data_path, variable.name)) driver.driver.variables.remove(variable) else: variable_names.add(variable.name) ```

You actually need to traverse the list in the reverse order. Corrected script using reversed:

import bpy

for _name in dir(bpy.data):

iterable = getattr(bpy.data, _name)
if not isinstance(iterable, bpy.data.objects.class):
continue
for id in iterable:
if not getattr(id, "animation_data", None):
continue
for driver in id.animation_data.drivers:
variable_names = set()
for variable in reversed(driver.driver.variables):
if variable.name in variable_names:
print("ERROR! ID driver '%s.%s' has several variables named '%s', removing the extra ones." % (id.name, driver.data_path, variable.name))
driver.driver.variables.remove(variable)
else:
variable_names.add(variable.name)

Sample file:
drivers-name-clash.blend

You actually need to traverse the list in the reverse order. Corrected script using **reversed**: ```lang=python import bpy for _name in dir(bpy.data): ``` iterable = getattr(bpy.data, _name) if not isinstance(iterable, bpy.data.objects.__class__): continue for id in iterable: if not getattr(id, "animation_data", None): continue for driver in id.animation_data.drivers: variable_names = set() for variable in reversed(driver.driver.variables): if variable.name in variable_names: print("ERROR! ID driver '%s.%s' has several variables named '%s', removing the extra ones." % (id.name, driver.data_path, variable.name)) driver.driver.variables.remove(variable) else: variable_names.add(variable.name) ``` ``` Sample file: [drivers-name-clash.blend](https://archive.blender.org/developer/F12749004/drivers-name-clash.blend)
Sybren A. Stüvel self-assigned this 2021-12-16 12:09:42 +01:00

This is indeed something to address. There is no use for multiple variables when they all overwrite each other's value anyway.

So think there should be a mechanism (maybe as part of driver_variable_name_validate ?) that should ensure unique names?

I agree, but not in that function. That now has a clear, single purpose, and I don't want to add more things to it.

This is indeed something to address. There is no use for multiple variables when they all overwrite each other's value anyway. > So think there should be a mechanism (maybe as part of `driver_variable_name_validate` ?) that should ensure unique names? I agree, but not in that function. That now has a clear, single purpose, and I don't want to add more things to it.

This issue was referenced by 4b21067aea

This issue was referenced by 4b21067aea415f7eb4604de6dd133a67a4063640

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#94116
No description provided.