Switching a Property's Unit in the UI

Can anyone please explain how to change a property’s subtype for a UI?

For example if I have a FloatProperty in a Panel representing a Property’s value and the value is rotation for one object and translation for another. I’d want to show the units ° and m, respectively.

In the following posts, it seems the answer is that Property’s subtype can only be set at creation. Would I need to create a FloatProperty for every possible subtype and switch or can it be done more neatly with one property?

https://blender.stackexchange.com/questions/237819/how-change-stringproperty-subtype-with-a-button

https://blender.stackexchange.com/questions/18686/setting-a-propertys-min-and-max-values-after-creation

Thank you!

semantically, i don’t know why you would ever want to use the same property to represent two completely different things. If you want to represent rotation and translation, use two properties- because rotation and translation are not the same thing, even if they can both be represented by a vector.

But yes, to answer your question- you have to set the subtype during property initialization. There’s probably a way to hack around this using the RNA or the property but it would be ill-advised.

1 Like

Thank you for the reply.