Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Prefab instance's root order is not being saved in scene file

Discussion in 'Prefabs' started by robal1991, Nov 7, 2019.

  1. robal1991

    robal1991

    Joined:
    Mar 31, 2016
    Posts:
    32
    Hello, i'm using Unity 2019.3.0b9 (but I've had similar problem on Unity 2017.4 as well). I have a problem with hierarchy order. I've managed to simplify the problem to a simple scene. My hierarchy looks like this:

    upload_2019-11-7_8-57-56.png

    I want it to preserve the order when I hit play. But somehow 3_Prefab instance goes before 2nd element and in play mode my hierarchy looks like this:

    upload_2019-11-7_9-2-25.png

    All Gameobjects in the scene have only RectTransform component. There are no scripts.

    I'm using prefabs for UI elements and the hierarchy order has to be preserved.
    When I looked in the scene file I see PrefabInstance section but strangely the m_RootOrder value is 1.

    upload_2019-11-7_9-3-50.png

    When I change it manually in the .unity file to 2, everything works like a charm. IMO somehow the scene does not save the root order of the prefab instance in the .unity file.
    Am I missing something? Am I doing something wrong?

    I want to add that I realized that in the PrefabInstance section there is a lot of unused overrides from previous "forms" of the prefab, which is kinda explaining why my scene files are so large... Maybe these unused overrides are generating the problem?

    That prefab modification of m_RootOrder on target fileID 0 can be also removed and everything is working as expected. Is there a better solution than manually editing scene files? I have a big project and lots of prefabs in scenes.

    Revert All changes on prefab instance also work, but this is unacceptable solution because I would need to recreate all prefabs basically from scratch again.

    Can I just safely remove all "- target: {fileID: 0}" modifications from my scene files? What does "fileID: 0" mean? How are prefab modifications sorted in scene file?

    I'm experimenting with this whole day and it seems to me that it takes the first m_RootOrder modified property regardless of target fileID? This behaviour is obviously very bad. I have more than 1 m_RootOrder modification from my prefab. Is this allowed with the new prefab system? Am I allowed to modified prefab's children root order? If not then it is reasonable that Unity reads the first rootOrder modification and assumes that it has to be done on the prefab root transform. I would have to reorganize my prefabs to meet new requirements.

    Is that correct?

    I'm attaching my sample project. Try to move prefab to the 3rd place, then save the scene, then hit play.

    Thanks for any help!
     

    Attached Files:

    Last edited: Dec 10, 2019
    phaserkitty likes this.
  2. NiallSoe

    NiallSoe

    Joined:
    Jan 30, 2018
    Posts:
    17
    Hi @robal1991

    I have seen this same issue in 2 separate projects now that share no code. I did report the issue to Unity but they could not reproduce it.

    The root of the problem is that there should only ever be a single m_RootOrder modification per scene prefab instance, you have 3 in your file.

    Looking back at my scene in source control, this is where the issue was introduced:

    upload_2020-4-25_14-49-6.png

    I believe this is when I added a structural change to my UI_System prefab to add a root SafeZone object, this would make sense as you can that the m_PrefabParentObject has also changed at the same time the extra m_RootOrder was added.

    Unity did provided me with a helper script to clean out the extra m_RootOrder properties, but unfortunately it does not work. On the latets version of my scene PrefabUtility.GetPropertyModifications() only sees 13 modifications whereas there are actually 15 listed in the YAML including the duplicates.

    Hopefully this information help Unity track it down.

    Niall
     
    Zerith likes this.
  3. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    755
    I see this fixed in 2019.3.5f1 (it may also be fixed in previous version, but this is the one I've upgraded to)