Naming material slots

Hello :wave:!

It seems it’s been an issue over the years - naming material slots:

I reckon there has not been any movement on this? I have a scenario where it would be incredibly useful to be able to name or add metadata to slots so I tried to make this possible on my own.

As it sadly seems to be impossible to add properties to MaterialSlot directly I ended up storing a collection property with entries for each slot on the object.

This becomes tricky (and hacky!) when trying to keep slots and their meta in sync, as the user can of course add, remove and shift slot positions.

What I ended up doing is create operators for all these actions and overriding a bunch of blender UI operators (i.e. CYCLES_PT_context_material, EEVEE_MATERIAL_PT_context_material) and make them call my operator which then calls the original op (i.e. bpy.ops.object.material_slot_remove()).

But yes, this feels pretty terrible as there’s obviously many ways this can break: users without the addon doing stuff on a file or other scripts acting on the slots. And I suppose things will fall apart with every new blender version.

So I’m wondering if someone has an idea on how to solve this in a better fashion?
Is there some way to reference into the meta data rather than per index?

Thanks a lot in advance!

seb

The sync work comes from keying metadata to the slot index. Key it to the material and it goes away.

Materials are IDs and take custom properties, and slots don’t: on 3.6 through 5.2 you get the same TypeError: bpy_struct[key] = val: id properties not supported for this type, with id_properties_ensure() answering This type doesn't support IDProperties. slot.name is read-only too. It’s the material’s name.

I tagged three materials, ran material_slot_move, then read back through slot.material['slot_meta']. All three right, still right after a slot removal, no operator overrides anywhere. The index-keyed version was wrong for two of three.

Gap: two slots sharing one material.