- Home /
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?
Answer by FortisVenaliter · Sep 19, 2017 at 10:17 PM
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.
That makes sense. I would say our scene in question does have a lot of nested UI components.
We have just the one single root-level Canvas. If I ins$$anonymous$$d set up additional Canvases in the hierarchy as children, grandchildren, etc. could that potentially make a difference, i.e. "simplify" the floating point calculations Unity has to keep doing, by reducing the transform depth of some objects? Or is the complexity of the operations based purely on absolute scene depth, versus "depth from Canvas"?
I mainly ask because I've already been considering adding sub-Canvases since it's supposed to be better for performance anyway, given how meshes are rebuilt and so on.
I couldn't say for sure, but it's worth branching to give it a shot.
Your answer
Follow this Question
Related Questions
Unity Editor - Scene view not redrawing 0 Answers
How to make buttons have sound when it is highlighted and clicked? 0 Answers
Strange UI scrollbar handle recttransform behaviour,Cant resize clickable area on UI handle 1 Answer
SVG Image quality when imported to UI is bad. 0 Answers
Is there a way to activate a timer from another scene? 1 Answer