Search Unity

UI always editing scene file

Discussion in 'UGUI & TextMesh Pro' started by makeshiftwings, Sep 19, 2017.

  1. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    For a year or two now, there's been a bug where UI that uses layouts or anchors in a scene causes it to constantly overwrite the position and size values in the scene whenever entering or exiting playmode or opening or closing the scene. It makes source control super annoying since the scene files are constantly being edited and changed even though there are no actual changes. Is there any way to stop it from doing this? I haven't narrowed down exactly which components cause it, but I'm guessing it's anything that uses stretch or that has more than one level of objects?
     
  2. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Are you using text assets? That would help to narrow down which object is causing it. I haven't seen that behaviour myself, but I would first double check what the exact changes are, and also disable all 3rd party editor extensions in case it's an editor extension causing it.

    Also check if you have any OnValidate calls that are changing any fields somewhere. I've seen that cause the scene to be updated in the past too.

    -sam
     
  3. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I've heard this reported from lots of people, and I don't think it has anything to do with 3rd party assets. If you have UI elements with children and use Layouts (like Horizontal Layout, Vertical Layout, etc) and/or anchors with stretch mode turned on, it basically keeps rewriting all the transform values that become grayed out with tiny changes constantly because it apparently recalculates the values all the time for no reason. The sane thing to do would be to only save the values for the Layout component; anything that's auto-calculated and grayed out should not be saved.
     
  4. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    I set up a small test in a new empty project and don't see that happening at all. With anchors set to stretch btw, nothing is greyed out. It really seems to me that there is something else in your project that is conflicting and causing it to happen. I'd suggest setting up a minimal reproducible project and submitting a bug report.

    -sam
     
  5. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Unity knows about it. There have been many bug reports. I was hoping to get help from anyone else who uses LayoutGroups and has to deal with this, not have someone who hasn't used LayoutGroups come in and demand that I prove they're broken without ever having used them himself. :p
     
  6. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    If you really need proof, you can't just use stretch, you have to use a LayoutGroup, like Vertical Layout Group. Add that to a panel. Make a prefab of something like a button or text element. Put a few copies of that prefab under the Layout Group. Now you will see that the transform values for those things in the layout group are greyed out. That's normal, that's not the bug. Save the scene, enter play mode, exit play mode, and you will see the scene has been modified again even though nothing changed. That's the bug.
     
  7. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Ok I see it happening now, but only when the child objects are prefabs. If they aren't prefabs it doesn't happen for me.

    Additionally, if I save the scene and check in the changes, then enter and exit play mode, Unity says the scene has changed but then the next time I save there are no changes to the scene.

    I found this one bug about it which is closed as "won't fix" for some reason but I can't find any justification for why they won't fix. Do you know of any other bugs logged for this issue?

    Personally I would log another bug. In fact I might, since I have a test case set up now.

    edit: actually I see another bug here which is apparently fixed in 2017.2.

    -sam
     
    gresolio likes this.
  8. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    During the era when the "won't fix" happened, Unity had said it was "expected behavior" to keep editing the scene file automatically because it had to auto-compute the values and floating point error made them change sometimes. Who knows, maybe they decided to try to fix it since then. I have a lot of complex UI and it happens in lots of cases other than this; LayoutGroup with some prefabs is just a very common one for anyone making UI with a list or grid.
     
  9. AronTD

    AronTD

    Joined:
    Aug 31, 2013
    Posts:
    22
    Having the same issue.