We had a run-in with maya units when referencing our rigs. Here’s what we figured out
- The type of the attribute matters a LOT in these cases, and that includes any custom attributes you create
- Attributes that deal with unit conversion are angle, distance, and unitless (default float attributes)
- Maya’s native units are centimeters and radians. Basically everything at the API level uses these units (with few exceptions)
How Unit Conversion connections work:
- If the type of the attributes to be connected matches (angle, distance, or unitless), then no conversion is added
- If the type doesn’t match, create a unit conversion node. EXCEPT if both ends are api native type for the current scene (unitless is always native type)
So a unitless attribute connected to a distance attribute when the scene is in centimeters will not create a conversion node. But the same connection made when the scene is in meters, or inches will. And a connection between distance and angle when the units are set to centimeters and radians will not create a unit conversion node.
Thoughts on conversion
Attributes of type distance or angle are always stored and passed in native units, but will be displayed in current scene units
You can prove this to yourself if you create a float attribute, and connect it to an angle. You’ll get a unit conversion node of
0.017 (degrees to radians). However, the controlled angle will display the same value as the controlling attribute. This is because the actual value passed is in radians, but there is an implicit conversion from radians to degrees for display in the UI.
In that case, because the float is connected to an angle when the scene is in degrees, maya assumes that you meant that attribute to be interacted with as degrees, and therefore any animation or whatever on that value will always be in degrees, no matter how you change the scene units because that attribute is unitless.
And If you didn’t do it like that, then when you referenced an already animated file into another with different units, then the animation would necessarily change
Our biggest takeaway from that experience was always always always make sure that when you create attributes that are supposed to be angles, you make the attribute an angle type, and when they’re supposed to be distances, you make them distance type. You can’t do that through the “Add Attribute…” menu item, you’ve gotta do it through code. We also had to go back through all our custom c++ nodes, update the attribute types, and recompile them to get the expected behavior.