Search Unity

Applying prefab changes changes RectTranform properties

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by GilCat, Oct 31, 2017.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    I'm having a weird problem that when i apply changes on a prefab it will change the transform positions of some of the nested children.
    The problem only seems to happen to objects that are 3 or more levels deep in the prefab hierarchy.
    I have tested this with Unity 2017.3.0b6 and 2017.3.0b7. This is very annoying since it completely breaks the prefab layout.
    Attached is a very simple project where this problem occurs.
    *Instructions*
    Open Main scene
    Select "ProblematicPrefab" in the scene hierarchy
    Click "apply" to apply changes to the prefab

    You will notice that one of the button will be replaced to some other position and also that the button label will automatic acquire some random offset.

    Thanks
     

    Attached Files:

  2. GreatVV

    GreatVV

    Joined:
    Feb 6, 2014
    Posts:
    3
    I have the same bug! And it is really bad one =(
     
  3. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    273
    I actually saw this today on 2017.2. It happend only when their game object was disabled. The images would jump to another location. But I could click revert after and they would go back to the original locations I applied it at. If they were not deactivated they would not move.

    I didn't look at the scene file to see if the changes were being saved in the scene file or not.
     
    GilCat likes this.
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    It works fine on Unity 2017.1 and at least until 2017.3.0b4. So something after that must have broken things up.
    This is really annoying and it is making impossible to edit prefabs :(
     
    Last edited: Nov 3, 2017
  5. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    Also confirm that Unity 2017.3.0b8 suffers from this.
     
  6. BlackGateDev

    BlackGateDev

    Joined:
    Jul 27, 2017
    Posts:
    9
    Any update on this? I'm on 2017.3.0f3 and still having this issue. The latest patch (2017.3.0p1) makes no mention of it.
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,187
    Expect to see a fix on this in the next or subsequent patch for Unity 2017.3.
     
  8. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    770
    Any workaround for this bug? I can't apply any changes to my UI prefabs as of now. Extremely frustrating.
    I didn't notice at first, and now most of my UI is all messed up.
     
  9. hangar

    hangar

    Joined:
    Feb 1, 2013
    Posts:
    16
    Did this get fixed in 2017.3.0p2? I don't see anything in the notes. Is there a Unity Issue Tracker # for this bug?
     
  10. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    146
    I'm still seeing the issue in p2 and I also can't see any editor fixes in the patch notes, so I'm guessing not. It's super annoying, my UI is wrecked! Fingers crossed a fix is in p3.
     
  11. BlackGateDev

    BlackGateDev

    Joined:
    Jul 27, 2017
    Posts:
    9
    p3 is out and no mention of this fix again in patch notes. Can we have an update on when to reasonably expect a fix?
     
    jhow77 likes this.
  12. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
    Also, another conversation going on here.

    This bug is driving me nuts! I'm using 2017.3.0f3 and can't figure out how to update my complex prefabs without them breaking! The worst part is I can't even tell if the Unity team is even paying any attention to it.

    Related Links:
    • Issue 968969 - Incorrectly closed and addressed as a "Duplicate Issue" for Issue 966172, which has a priority of 2, severity of 3. If you can please vote for the issue and post a comment asking them to reopen 968969.
    • Issue 964111 - Closed and noted as "Fixed", which it obviously is not. Or else, we wouldn't be having this discussion.
    Can somebody on the Unity team atleast confirm that this is being addressed?! Has anyone found a workaround?
     
  13. ekaralar

    ekaralar

    Joined:
    Jan 13, 2015
    Posts:
    10
    This really is unacceptable.

    @unityteam: Care to give an update and eta for a fix?
     
  14. tarmo-jussila

    tarmo-jussila

    Joined:
    Jun 4, 2015
    Posts:
    6
  15. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    272
    We're on p3 and this is still an issue. Can we get someone to earnestly fix this issue and send out a p4 soon? I have a project that is effectively dead because of this issue.
     
    jhow77 likes this.
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    964111 is fixed. We are currently backporting the fix to 2017.3. The fix has not yet landed into the 2017.3 patch release branch yet so unfortunately I can't give a patch version yet. I'll post the version when I have it but keep an eye on the patch release notes for the bug number 964111 just in case it slips by me.
     
    Shiffty, Zwilnik and Kumo-Kairo like this.
  17. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    246
    What is the latest version of Unity that isn't affected by this bug?
     
  18. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    75
    I think 2017.1 is unaffected.
     
  19. Thovex

    Thovex

    Joined:
    Jan 13, 2017
    Posts:
    1
    2017.3.0f3 works fine too. Issue persists on unity 2018.1.0b4
     
  20. holgk

    holgk

    Joined:
    Aug 26, 2013
    Posts:
    10
    I've the problem too. I'm using Unity 2018.1.0b4.
     
  21. enchiridion

    enchiridion

    Joined:
    Oct 29, 2014
    Posts:
    56
    I discovered this only happens if the prefab is parented in a Canvas. If you simply drag it into the scene it works as intended. However, this is undesired behavior and must still be fixed ASAP.

    2017.3.0p3
     
  22. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    146
    Lol according to patch notes this is still not fixed in p4. I feel like I'm taking crazy pills, is this not a pretty severe bug?

    As an aside, in my case disabling all canvas scalers in the prefab stops the broken behaviour. So I'm saving changes to the prefab with the scalers turned off, and I have a script attached to the prefab finding all scalers in Start() and enabling them. Works fine for now, YMMV.

    Code (CSharp):
    1. void Start () {
    2.         CanvasScaler[] canvasScalers = FindObjectsOfType(typeof(CanvasScaler)) as CanvasScaler[];
    3.         foreach(CanvasScaler scaler in canvasScalers) {
    4.             scaler.enabled = true;
    5.         }
    6.     }
     
    bzor likes this.
  23. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    It is on the way to 2017.3
    The issue was fixed a few weeks ago however it takes time to get into a patch.
    A backport must be created, approved by area owners and tested. We can't just throw it into the next patch, that's how things break even more.
    This fix has now been approved and tested locally. It is waiting to be merged into the 2017.3 patch branch, during this stage we then re run all the automated tests to ensure that the new fixes for that batch dont conflict with each other.
    So providing nothing goes wrong with the final stage then it should be in the next patch.
     
    enchiridion likes this.
  24. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    146
    @karl_jones thanks for the update, it's the not knowing that is frustrating. There's been a fair few people 'screaming into the void' on this one trying to get some sort of timeline from someone. And now we have one! Thanks again.
     
    karl_jones likes this.
  25. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    No problem. Its not always easy to give a timeline as any of the above steps can cause big delays or even stop the whole process :(

    Update:
    The fix has now landed into our 2017.3 patch branch. It will be available in 2017.3.1p1
     
    Last edited: Jan 29, 2018
    adslitw likes this.
  26. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    272
    2017.3.1 isn't even out yet? How long are we going to have to wait for p1? This issue is crippling.
     
  27. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    2017.3.1f1 is due this week, p1 is due next week.
     
  28. larry_kirschner_ict

    larry_kirschner_ict

    Joined:
    Jan 4, 2018
    Posts:
    3
    How can you call this issue fixed if there's no downloadable patch release and no workaround?

    If there's a workaround for this issue, that needs to be brought to light here/now. If there's no workaround and no patch, then you're effectively saying "suspend work on your project until we fix this bug." Is that Unity's position?
     
    Wahooney and enchiridion like this.
  29. larry_kirschner_ict

    larry_kirschner_ict

    Joined:
    Jan 4, 2018
    Posts:
    3
    This is the best workaround I was able to come up with. Basically, add an instance of this component to any of the objects in your prefab that are getting messed up:

    Code (CSharp):
    1.  
    2. using UnityEngine.EventSystems;
    3. using UnityEngine;
    4. [ExecuteInEditMode]
    5. public class UnityGetYourActTogetherOrGiveMyMoneyBack : MonoBehaviour
    6. {
    7.     public Vector3 m_anchoredPosition;
    8.     void Start()
    9.     {
    10.         GetComponent<RectTransform> ().anchoredPosition = m_anchoredPosition;
    11.     }
    12.     #if UNITY_EDITOR
    13.     void Update()
    14.     {
    15.         if (Application.isPlaying) {
    16.             return;
    17.         }
    18.         m_anchoredPosition = GetComponent<RectTransform> ().anchoredPosition3D;
    19.     }
    20.     #endif
    21. }

    For me the layout problems happen both at edit time (when I apply a prefab) *and* at run time (when I instantiate a prefab, even if it's correct in asset form).

    The one saving grace *seems* to be that the set of objects in a prefab that get affected is roughly consistent and it's not all of them. So I'm just adding the above component to the affected objects under each prefab.
     
  30. enchiridion

    enchiridion

    Joined:
    Oct 29, 2014
    Posts:
    56
    My thought's exactly.
     
  31. TheDemiurge

    TheDemiurge

    Joined:
    Jul 26, 2010
    Posts:
    41
    Just finished opening with 2017.3.1p1 and it does look fixed now.
     
  32. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    770
    How do you have access to 2017.3.1p1? Are you a time traveler from the future?
     
  33. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    I think you may be confusing 2017.1.3p1 with 2017.3.1p1.
    It will be fixed in that as its before the regression came in.
    ETA is still next week. It is currently going through QA testing.
     
  34. TheDemiurge

    TheDemiurge

    Joined:
    Jul 26, 2010
    Posts:
    41
    You're right. That explains why BuildTarget.StandaloneOSX got "reverted"... Dammit...
     
  35. dugsteen

    dugsteen

    Joined:
    Dec 9, 2015
    Posts:
    5
    I can also confirm. Thank you.
     
  36. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    417
    This bug is gone in Unity 2018.1.0b5
    Finally :)
     
  37. PBaille

    PBaille

    Joined:
    Aug 6, 2016
    Posts:
    1
    Weird ! I still having this issue...
     
  38. P4blo

    P4blo

    Joined:
    Dec 12, 2012
    Posts:
    18
    My temporal solution:

    Code (CSharp):
    1. /*
    2. *
    3. * This script is made for solving the f****ng problem with the Editor that changes the position of the UI elements everytime you Apply
    4. * changes to a prefab.
    5. *
    6. * https://forum.unity.com/threads/applying-prefab-changes-changes-recttranform-properties.502542/
    7. *
    8. */
    9.  
    10. using UnityEngine;
    11.  
    12. public class F***ingEditorBugSolver : MonoBehaviour
    13. {
    14.  
    15.     #region MonoBehaviour methods
    16.  
    17.     RectTransform _rectTransform;
    18.  
    19.     private void Awake()
    20.     {
    21.         _rectTransform = GetComponent<RectTransform>();
    22.  
    23.     }
    24.  
    25.     private void Start()
    26.     {
    27.         if(_rectTransform != null)
    28.         {
    29.             _rectTransform.anchoredPosition3D = Vector3.zero;
    30.         }
    31.  
    32.  
    33.     }
    34.  
    35.     #endregion
    36.  
    37. }
    Just attach this script to those GOs that change their position in the editor when the "Apply" button is pressed.
     
    Last edited: Feb 7, 2018
  39. jbergs

    jbergs

    Joined:
    Feb 13, 2014
    Posts:
    9
    This is really a problem.. it's still there for me in 2018.1.0b5.
     
  40. musickgm

    musickgm

    Joined:
    Mar 19, 2016
    Posts:
    15
    @karl_jones is this still coming out this week? Perhaps today or tomorrow? Or did it already come out and I can't find it?
     
  41. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    59
    Wheeeeere is the update?!
     
  42. enchiridion

    enchiridion

    Joined:
    Oct 29, 2014
    Posts:
    56
    Yeah windows as well, but he did say it will be fixed in 2017.3.1p1 not f1 ;)
     
  43. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    59
    Where is 2017.3.1p1? Can't find it. Are you sure about the version? On the patch page the first version you see is 2017.1.3p1, not 2017.3.1p1
     
    musickgm likes this.
  44. stalker_shin

    stalker_shin

    Joined:
    Jun 25, 2016
    Posts:
    13
  45. zhuyunxiang1984

    zhuyunxiang1984

    Joined:
    May 25, 2017
    Posts:
    1
    Code (CSharp):
    1. using UnityEngine;
    2. #if UNITY_EDITOR
    3. using UnityEditor;
    4. #endif
    5.  
    6.  
    7. [ExecuteInEditMode]
    8. public class TMPBugSolver : MonoBehaviour
    9. {
    10. #if UNITY_EDITOR
    11.     void OnEnable()
    12.     {
    13.         PrefabUtility.prefabInstanceUpdated += eventon_prefab_instance_updated;
    14.     }
    15.     void OnDisable()
    16.     {
    17.         PrefabUtility.prefabInstanceUpdated -= eventon_prefab_instance_updated;
    18.     }
    19.  
    20.     private GameObject m_new_instance;
    21.     private GameObject m_old_instance;
    22.     private string m_childpath;
    23.  
    24.     private void eventon_prefab_instance_updated(GameObject instance)
    25.     {
    26.         if (PrefabUtility.GetPrefabType(instance) != PrefabType.PrefabInstance)
    27.             return;
    28.         if (instance != gameObject)
    29.             return;
    30.         Debug.Log(instance + " click apply");
    31.         var pref = PrefabUtility.GetPrefabParent(instance);
    32.         //var path = AssetDatabase.GetAssetPath(pref);
    33.         //Debug.Log(path);
    34.         m_old_instance = instance;
    35.         m_new_instance = PrefabUtility.InstantiatePrefab(pref) as GameObject;
    36.         Invoke("delaydestroy", 0.1f);
    37.  
    38.         m_childpath = findchildpath(instance.transform, Selection.activeTransform);
    39.         Debug.Log(m_childpath);
    40.     }
    41.     private void delaydestroy()
    42.     {
    43.         GameObject.DestroyImmediate(m_old_instance);
    44.         if (m_childpath == null)
    45.         {
    46.             Selection.activeGameObject = m_new_instance;
    47.         }
    48.         else
    49.         {
    50.             Selection.activeTransform = m_new_instance.transform.Find(m_childpath);
    51.             EditorGUIUtility.PingObject(Selection.activeTransform);
    52.         }
    53.  
    54.         m_old_instance = null;
    55.         m_new_instance = null;
    56.         m_childpath = null;
    57.     }
    58.  
    59.     private string findchildpath(Transform parent, Transform child)
    60.     {
    61.         if (parent == child)
    62.             return null;
    63.  
    64.         string path = child.name;
    65.         child = child.parent;
    66.         while (child != parent && child != child.root)
    67.         {
    68.             path = child.name + "/" + path;
    69.             child = child.parent;
    70.         }
    71.         return path;
    72.     }
    73.  
    74. #endif
    75. }
    76.  
     
    Last edited: Feb 11, 2018
  46. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    272
    How are Unity not freaking out about rushing this fix out?

    Even if 2017.3.1p1's release notes were just:
    • Fixed ancient UI bug (sorry!)
    That would be something. But this deafening silence from Unity (with exception of @karl_jones [Sincerely, thanks for trying to keep us up to date!]) is telling, because I can guarantee, we who have complained here are a vocal minority, there are many more people with this issue (I was a member of that silent minority 'til I had enough of what should be a priority issue that's been around since uGUI was released).

    I have 3 current projects that have cumulatively had multiple weeks worth of lost productivity due to this bug. We've had to adopt stupid practices now (which bypass some of Unity's better features) just to circumvent this, leaving our projects in unacceptably bad shape.

    What do we have to do to get this issue fixed in a timely manner?
     
    musickgm likes this.
  47. musickgm

    musickgm

    Joined:
    Mar 19, 2016
    Posts:
    15
    @Wahooney couldn't agree more. I'm following another thread and @karl_jones says:
    "I'm told that they had to do a rebuild (last minute fixes). It should be ready for Monday."

    I'm crossing my fingers for that.
     
  48. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    Yes. Sometimes an issue is found in a patch during testing and we need to fix that as well, then rebuild and retest. This adds up and delays things but its better than releasing a patch with more problems. We understand this is a problem but every fix comes with a risk that it may actually break other things so we always have to be sure that it does indeed fix the situation and not actually make things worse(we have learned this the hard way in the past!).

    Im told things should be ready Monday.
     
    AlanMattano, Harinezumi and musickgm like this.
  49. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,459
    Oh yes I do. I have lost track of time o_O
    Its being verified by our US team so bear in mind the time difference.
     
    Last edited: Feb 12, 2018
  50. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    59
    I neeeeeeeeeed it. Noooooooooooow!
     
    jhow77 likes this.