Custom attributes on existing controls?

Hello,

Not sure I’m approaching this correctly, but I’m trying to provide custom data to existing controls - like Buttons.
I’m trying to build an Editor window with buttons for common prefabs in the project.
I would like the buttons themselves in the UXML to define which prefabs to show. In my mind, it would look something like:

<ui:Button text="Game Manager" prefab="GameManager" prefab-folder="Wherever" />

Then in my editor window I would iterate over all the controls with the “Prefab” property, add an onClick to each one, and on the onClick callback get the property value and open the relevant prefab.

Is that possible? I could of course create custom controls for these, but in my mind that means a lot more code, not to mention creating new classes for each such control - whereas if I could just provide any custom attributes on any type of control that would be much simpler I believe.

Hi,
No this is not possible, if an attribute does not have a field (through UxmlTraits or UxmlAttribute) then it will not be available through the element. The additional attributes would be stored in the element but require internal access, I would not recommend trying to access them as internal code can and often does change. You will need to create custom controls to access these safely.

Okay, thanks for the response!

Out of interest is it that this was just never needed, or is there a technical limitation behind it?
Just wondering as that would make working with it much quicker (IMO) - especially for Editor tools where maybe you don’t want to have to write lots of classes for every window you make.
Being able to do something like (taken from JS):

document.querySelectorAll('[attribute-name="value"]')

I think would be really useful.