Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Prefab modifications are constantly changing serialized data order and cause version control noise

Discussion in 'Prefabs' started by Xarbrough, Aug 5, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I believe I have already seen this issue as a bug report somewhere, but cannot find it anymore. Please let me know if this is being worked on or if anyone has any ideas what to do against this:

    PrefabModificationsRandomOrder.jpg

    We are on Unity 2019 and at some point in the past a dozen of our prefabs have started changing every time the project is saved even though nobody has touched these assets. The values itself do not seem to change, but the order in which these modifications are saved to disk. This is causing a really big annoyance for us because we are working in a team and team members are constantly confused why these assets show up as changed and cause merge conflicts, when they shouldn't.

    Unity is notorious for setting files dirty even though nothing has changed, this is a well-known problem and other software such as PlasticSCM actually patches some of this up by ignoring files which have their timestamp changed, but not their content. However, in this case with prefabs, the contents change their order which causes a lot of noise in our version control system.

    Again, I believe this is a known bug, but please let me know what the status is, as I cannot find it in the issuetracker. Thank you!
     
  2. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    106
    I was just complaining about this / confirming with some other folks! We're seeing this two across multiple 2019 projects. Super annoying. We have hundreds of prefabs in our projects and this can take a long time if you want to be able to verify that no changes were made. When we see this manifest, its just taking the data we have and reordering it in the prefab, no actual changes are being made.
     
  3. Elliott-Mitchell

    Elliott-Mitchell

    Joined:
    Oct 8, 2015
    Posts:
    88
    By chance, do you have auto-save enabled for prefabs?
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    No, at least not on my machine. Maybe some of our developers have it on, but the changes already happen when these specific prefabs are loaded into memory (either because a scene was openen which contains them or if they have been selected in the inspector during the editor session), and then the project is saved.
     
  5. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    SpinningDonut.gif
    The problem is getting worse every week. We've now found cases were the affected prefabs are being reimported whenever anything changes in the project and can even become stuck in an import loop. I've reported an issue with reproduction case, but I'm still waiting for a reply. I believe it's rather difficult to reproduce for QA. The issue does not happen when one works on a single user machine, it requires at least two different users/computers to cause the serialization to randomly change. I assume it's mainly because the asset import is not deterministic and therefore, whenever one of my team mates opens their project, Unity imports the prefabs differently, but for unknown reasons this also changes the actual prefab files on disk. To reproduce this, one must setup a multi-user environment with version control. I've explained it in the bug report, so let's see what they say.
     
  6. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
  7. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Thanks, that's great news! :) Is there a different issue id I can track or how will we know when the fix has landed?
     
  8. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    106
    Thanks for the update @SteenLund! (I'd also love a public issue ID for this one.)
     
  9. marcin-huuuge

    marcin-huuuge

    Joined:
    Sep 5, 2018
    Posts:
    15
    I confirm it happening on 2019.1.14f1 and 2018.3.6f1. It also happens in the serialized scene file in the prefab modification list. This is very annoying and slows our work down. Instead simply committing all the changes I've made I have to go through list of changes and stage chunks of real changes one by one. Please fix this.
     
  10. SeductiveMango

    SeductiveMango

    Joined:
    Jun 3, 2019
    Posts:
    1
    Happening on 2019.1.5f1. Making it neigh impossible to work on entire prefabs since it just constantly is updating.
     
  11. mcarriere

    mcarriere

    Joined:
    Sep 14, 2012
    Posts:
    106
    @SteenLund Any updates or versions we can be looking forward to for this fix?
     
  12. Vince-Chimp

    Vince-Chimp

    Joined:
    May 28, 2018
    Posts:
    42
    I'd also be interested in a bug reference to track this. @SteenLund
     
  13. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
  14. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Happening in 2019.2.1f1 as well :\
     
  15. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Same here, exactly same behavior, ordering of modifications changes.
    In example below it's moved 50 lines up for no particular reason.

    It's big issue for us, because we use nested prefabs heavily and this change triggers reimport of all dependent prefabs, which can take minutes. Worse this happens when prefab is clicked in project, because it opens it in inspector and then it saves it right away.

    Naive approach to fixing this seems like sorting modifications by property path.

    upload_2019-10-21_16-45-34.png
     
    JesOb likes this.
  16. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    This issue has a been fixed for 2020.1 and backports are in progress.
     
    phobos2077, Peter77, OndrejP and 2 others like this.
  17. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Great news! Thank you!
     
  18. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Has the fix been backported to 2019.2 yet? If so, what version? :)
     
  19. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    This fix has been verified in the following versions:
    2019.3.0f1
    2019.2.14f1
    2018.4.14f1
     
    hnngaf likes this.
  20. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Great! Looking forward to trying it soon :)
     
    Mads-Nyholm likes this.
  21. ScallyGames

    ScallyGames

    Joined:
    Sep 10, 2012
    Posts:
    44
    @Mads-Nyholm has the fix already landed? I am still experiencing this issue in 2019.3.0f6.
    Namely shifted property blocks as described by @OndrejP and arbitrary changes of floating point values.

    I'd have to verify again but I think it happens even when working locally on one machine. I save a scene/prefab, commit to version control, reopen the scene, save again (without doing any changes) and have changes in version control.
     
  22. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    217
    Can you post a screenshot of the diffs you are getting?
     
  23. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    If the scene gets dirty by simply opening the scene it means you have a script that makes changes to th scene during load. This could easily explain the differences you seen in version control.

    I have seen plugins that would destroy and recreate objects during load of a scene, causing blocks of changes in the scene file. If this is happening to you there is nothing we can do about this, you will have to figure out which plugin/script that does this and contact the author.
     
  24. ScallyGames

    ScallyGames

    Joined:
    Sep 10, 2012
    Posts:
    44
    @SteenLund thanks for the heads-up, that might very well be the case. I will check if there is any script doing modifications and open a new post in case the problem still persists, referencing this one.
     
  25. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    I'm still getting some noise when using AssetDatabase.ForceReserializeAssets compared to opening prefab in PrefabStage and saving.

    When using AssetDatabase.ForceReserializeAssets, I get the change on screenshot below.
    When I open prefab in PrefabStage and save it, the change goes away.

    This is very annoying. I use AssetDatabase.ForceReserializeAssets after Unity upgrade or script change (e.g. new field). The reason for this is I want to make clear distinction in VCS between intended design changes and structural changes.

    When I'm checking commits by other team members and most changes are structural changes unrelated to the work they did, the process gets slow and annoying.

    upload_2020-6-2_6-50-19.png
     
  26. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    I've made a project with easy repro:
    (Case 1252436) AssetDatabase.ForceReserializeAssets causes VCS clutter
     
    Peter77 likes this.
  27. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @OndrejP

    Thanks we will take a look.
     
    OndrejP likes this.
  28. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Peter77 likes this.
  29. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    Unity and version control is just broken. I installed the latest fixes with glee thinking great no more problems of being completely unable to see what is actually modified and what isn't. No such luck, every single commit random stuff shows up as modified when it isn't, it's a complete mess. Something in serialisation just doesn't work properly and prefabs, assets and materials can be randomly flagged as modified when they aren't. Currently running 2018.4.25 and the problem is no better for the recent fix.
     
  30. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It's worth noting that the fix that makes serialization deterministic will itself change each affected asset one time (because the serialization order is different with the fix) but after that it shouldn't change anymore. If you're seeing the serialization order change *multiple* times for the *same* asset after upgrading to the Unity version with the fix, we'd be interested in being able to reproduce that. Is that what you're seeing?
     
    OndrejP likes this.
  31. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    yes as far as I can tell it just constantly changes. If I submit to svn a new prefab any developer checking that out will end up with a modified version, which he then commits, then I get notification that it's modified and check it out and it gets modified again and then I have to commit it and it's just never ending.
     
  32. cassidycurtis

    cassidycurtis

    Joined:
    Apr 8, 2019
    Posts:
    6
    My team is using 2019.4.2f1, and we've encountered this same problem.

    My not-terribly-scientific analysis of what's happening: there seem to be two distinct ordering schemes (call them "A" and "B"). Each scheme is pretty consistent with itself, but the two are completely different from each other. Which one you get depends on which actions you do in the editor.

    If you edit the prefab directly and save it, you get scheme A.
    If you modify any value in a prefab from within a scene, and select "Apply to Prefab" from the dropdown menu, you'll get scheme B.
    Running ForceReserializeAssets from within a script also gives you scheme B.

    Our workaround, which seems to be working okay so far, has been to run ForceReserializeAssets whenever we notice big, unexpected changes to our prefabs. (Of course it'd be even better if Unity itself would do this consistently so we wouldn't have to!)
     
  33. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
  34. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I am still facing the same issue now, I am using Unity 2019.4.22f1. If we load a prefab into memory through Addressables, and change the prefab's property instead of instantiating a copy of it. Once we exit the PlayMode, we will see that the prefab preserves the modifications that were done during runtime. This causes source control noises and makes it really hard to distinguish the changes that are done by human and the changes that are accidentally introduced by runtime script.
     
  35. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I would say this is a different topic and also expected at least in my understanding. If you load a prefab at runtime in the editor and change it, you're deliberately changing an asset. That's the same way it works if you load a material, etc.

    However, in my original post, I was reporting issues about Unity changing the serialized data at seemingly random times without me actually making any changes to them. But in the meantime many of these bugs seem to have been fixed.

    I personally wouldn't want Unity to support any special behaviour where they would have to copy the source asset to create an in-memory copy that protects the serialized data, because it would affect performance and probably introduce more new bugs, like they did when Addressables suddenly decided to call OnEnable twice for all assets (because they were copied in memory). Better stick to the well-known behaviour where the user takes care of not accidentally editing assets at runtime. You can always copy things yourself if needed.
     
  36. dpt2

    dpt2

    Joined:
    Jun 15, 2021
    Posts:
    50
    Soo, almost 2 years later ... about that fix? Still happens in 2021.1

    EDIT: Fixed in 2022.1.0a3? Kidding me? Such BS that Unity gave up on patches. "Want a fix? Use our unstable version and mess up your live project with +100 other bugs Unity ignored since investors want features, not stability!"
     
    Last edited: Aug 18, 2021
  37. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23
    In the 2020.3.25f1 version, we still suffer from this issue.
    Any progress on this?