RectTransforms constantly being modified in Edit mode, marking scene dirty

We have a scene with nothing but a Canvas object and a bunch of children, representing our app’s different menu screens. For some reason when we have this scene open in the Editor, it is continuously being shown as dirty as though something has changed, even if the developer hasn’t made any changes to the scene. And if you save the scene’s “changes”, diffs actually show up in version control (we have asset serialization set to Force Text, so it’s possible to view, albeit not necessarily understand, the underlying YAML). Apparently what’s constantly changing are various RectTransform values - size deltas, positions, anchors, and so on. Due to how convoluted the YAML is it’s near impossible to tell specifically which RectTransforms are changing. Regardless, this is a real pain point for our team since not only is it frustrating having constant prompts about unsaved changes, but when actual changes are made, we have to try and separate the “real” changes with the erroneous ones in our git commits.

I’ve tried searching through our solution for any uses of EditorUtility.SetDirty as well as any uses of Undo and the few that exist are not even a part of this scene. I’ve tried disabling upper-level RectTransforms in the scene to try and narrow down the offender(s) but it feels like I’m getting inconsistent results. I want to believe there’s something simple in the scene hierarchy causing this, though I can’t find any similar cases through Googling my issue. Does anybody have suggestions for what to look for that I haven’t already tried? Or is this perhaps a Unity bug that I should report?

So, I have seen this too, especially when you have a lot of RectTransforms nested in a Canvas.

The problem seems to stem from floating-point precision issues in the hierarchy. This is just conjecture on my part, but I’ll try to explain what I think is happening. Basically, each RectTransform stores it’s information relative to it’s parent, but using the internal values. When viewing it in the inspector, it converts those internal values to friendly values, using it’s parent’s values to assist. When the inspector values are changed, it saves it back to the markup data files. But, when you have a deeply nested hierarchy, more operations are happening between those steps, and those conversions introduce floating point errors that it sometimes sees as a change, and decides to write them to the files, causing the issue you’re seeing.

I’ve definitely noticed that the issue becomes more pronounced the deeper the RectTransforms nest.

Unfortunately, I don’t know of a fix other than trying to reduce the number of levels in your hierarchy. And that’s certainly not always possible.