Search Unity

Applying prefab with inactive children and TMP element breaks layout

Discussion in 'UGUI & TextMesh Pro' started by GilCat, Dec 12, 2017.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I'm facing a bug with UI + Text Mesh Pro where when i apply a prefab it will break layout settings only if i have UI gameobjects disabled.
    Attached is a sample project and here are the reproduction steps:
    1. Unzip the attached project
    2. Open "Main" scene
    3. Go to hierarchy "Canvas -> Panel" and disable child gameobject "Button"
    4. Apply prefab
    5. Activate back "Button" gameobject and see that it's text label is out of position

    NOTE: This only happens if Canvas Scaler is set to *Constant Physical Size* and there is one Text Mesh Pro object in the prefab hierarchy
    Use Unity 2017.3.0f2 and TMP from Asset Store

    *Before applying steps*
    before.jpg

    *After applying steps*
    after.jpg
     

    Attached Files:

    MrEsquire likes this.
  2. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    This one seems related to what we have in Musicuso project.
     
    GilCat likes this.
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Could you please also send this as a bug report via the bug reporter?
     
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I have submitted a bug via Unity Bug Reporter prior to this post. Got a reply from the team that does not solve my problem. (Case 977959)
    Is that enough?
     
    LeonhardP likes this.
  5. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Reply from Unity QA was.
    Please try setting the pivot point on the Button to be at the exact center (X 0.5, Y 0.5), this should make the button's label appear correctly.

    That works on the actual example i've posted but we don't always want to have the pivot at that point and it doesn't clear the fact that there is something there to be fixed. I believe that they are looking into that :)

    Thanks Unity QA for looking into this :)
     
  6. BoaNeo

    BoaNeo

    Joined:
    Feb 21, 2013
    Posts:
    56
    I have a similar problem but in my case the TMP object is not even related to the prefab (It appears as if a single random TMP instance gets moved to a completely random position). I've submitted a bug report, but I'm also rolling back to 2017.2 since this is the third destructive bug I've found since upgrading to 2017.3.
     
    GilCat likes this.
  7. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    That also happens to me!
    And this bug is still present in Unity2017.3.0f3
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just sharing that I had another user report a similar issue with the TMP Dropdown which appears to be related to object re-parenting. In this particular case, the Scrollbar is placed incorrectly after calling RectTransform.SetParent().
     
    Last edited: Dec 22, 2017
  9. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Yes some combination of scrollbar or scrollview with tmp is causing it. Please we need fix for this. M.
     
  10. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Also using an horizontal layout group, is causing some issues on the first element of the group. It keeps resetting the coordinates of the TMP transform after applying the changes to the prefab. (In this case I'm using the paid version of TMP)
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    TMP is not causing the issue but instead exposing that something related to scene hierarchy and parenting of objects is not behaving correctly in 2017.3.

    For instance, while trying to figure out why the Scrollbar of the TMP Dropdown is not in the correct position, I discovered that placing the Scrollbar object in the Template before the Viewport object works correctly. Looking more closely at this reveals that in one case the Anchored Position.x is -80 while in the other it is 0.

    I will reach out to the appropriate folks at Unity about this once they are back from the Holidays.

    That could be different (not sure) so could you provide me with more details like a scene setup or repro project via PM or Unity bug report?
     
    dadude123 likes this.
  12. Vekta

    Vekta

    Joined:
    Jun 22, 2014
    Posts:
    9
    Any short term solutions for this, spent all day repositioning objects that have broken. :(

    Another issue is Prefabs have been wiping out any data links that are not within their hierarchy when updating (applying), this has been happening since 2017.1
     
    Last edited: Dec 24, 2017
  13. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    42
    Had this bug too. It changes position of UI elements inside scene even outside prefab, ui elements in my scene use anchored positioning.
    In my case layout breaks with TextMeshProUGUI in hierarchy and enabled CanvasScaler in Canvas. So I disable CanvasScaler and enable it after all prefabs were applied and saved.
     
    plipking likes this.
  14. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    In my example above you don't even need any drop-down or layout elements, just having that TMP text in the scene is enough. The particular case I've posted is definitely related to TMP since it doesn't happen if I use UI Text with the exact scene hierarchy.
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I tested your example setup in Unity 5.5 thru 2017.3 using the current and previous version of TMP and this behavior can only be observed in Unity 2017.3. In all cases, the Anchored Position of the child object (either the Scrollbar or the Text) gets modified which results in this incorrect behavior.

    This is definitely an issue that needs to be addressed. I see a few changes that were made in Unity 2017.3 that could be the source of this new behavior. I'll talk to the folks who made the changes once they are back from the Holidays.
     
    GilCat likes this.
  16. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    And if possible please write internal test case. :)
     
  17. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    42
    Hello, another bug case with easy to reproduce project 979554 https://issuetracker.unity3d.com/is...ther-ui-elements-when-canvasscaler-is-enabled , its setup uses anchored positioning. Looking forward for patch, thanks.
     
    Last edited: Dec 28, 2017
  18. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    Any way to get around this while waiting for an update?
     
  19. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Yes. Not applying prefabs :) :) :) :)
     
  20. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The behavior also changes if the prefab is disabled in the scene. This is also affected by the CanvasScaler which depending on the change, you could disable before apply.
     
  21. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    53
    Had to revert to a backup from this, made a huuuuge mess of my menus. Even if I got them all back to where they should be, as soon as I saved the scene the sliders/dropdowns/TMProUGUI objects would move back to the incorrect position. Happened if I reverted any prefab in the scene as well since I was trying to do that to fix their anchored positions but as soon as I reverted one the rest would go all over the place again.
     
  22. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Stephan :) what if canvasscaler is part of the prefab itself :):):) how can i disable it??? :) :) :)
     
  23. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    As it relates to prefabs, I am only getting the issue when using "Apply" on a prefab that is disabled. Using "Apply" on a prefab that is enabled appears to work as expected. If that is not the case for everyone, please Let me know and provide the steps to reproduce it.

    Again, this is an issue that needs to be fixed. At this point, I am just trying to find some potential workaround until a proper fix is made available.
     
  24. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Not only that. What I observe is that if we have parts of the prefab disabled. I mean some subobjects. Then we also get messed prefabs when trying Apply or Revert.
     
  25. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    It seems to screw up _mostly_ the ones that are disabled, but it does affect some enabled elements sometimes, too. The effect is the same for an enabled objects, but it seems to do it only for a single object (the first one in hierarchy?). In my case it's always been a TMPro text object.

    I have a UI canvas prefab object that is used in multiple scenes, and it has multiple popups and such that need to be disabled, so none of these workarounds are really of use for me. :|
     
  26. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    However, the same bug affects all RectTransform objects for me, not just TMPro ones.
     
  27. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    Another note: Once the bug happens after Apply, Revert doesn't bring back the working one, it remains broken.
     
  28. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    If you Apply then when your Revert your are always reverting to that broken prefab. Here having your stuff in a version control system is handy to avoid major frustrations :p
     
  29. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I have managed to narrow this down to accessing any property or function of any RectTransform when the Canvas Hierarchy is being modified / in flux which happens during object instantiation or when using "Apply" or "Revert" on a prefab contained in this hierarchy.

    As it turns out, TextMesh Pro uses the OnRectTransformDimensionsChange() callback to know when the RectTransform size has changed and thus accesses the properties of its RectTransform which in these cases happens when the Canvas hierarchy is being modified and thus results in these reported issues.

    Adding the following script to some new child GameObject of a Canvas which also contains a Prefab and a CanvasScaler will reproduce the behavior when using "Apply" on the prefab.

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class UI_Object : Graphic
    5. {
    6.     protected override void OnEnable()
    7.     {
    8.         Debug.Log("OnEnable()");
    9.     }
    10.  
    11.     protected override void OnDisable()
    12.     {
    13.         Debug.Log("OnDisable()");
    14.     }
    15.  
    16.     protected override void OnRectTransformDimensionsChange()
    17.     {
    18.         Debug.Log("OnRectTransformDimensionsChange() has been called.\nNew size is (" + rectTransform.sizeDelta);
    19.     }
    20. }
    upload_2017-12-28_4-30-10.png

    Given this issue could affect anyone using these or similar callbacks in their own scripts / projects, we'll need to get a proper fix on this. Like I said before, I'll share my findings with the appropriate folks at Unity as soon as they are back from the holidays.

    Hopefully, this can get fixed shortly, if not I already have a potential way to side step the issue in the case of TextMesh Pro. I'll provide feedback as soon as I have had a chance to discuss this internally.
     
    Last edited: Dec 28, 2017
    GilCat likes this.
  30. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Thank you Stephen for narrowing it down. Does anyone know if the same bug occur when using nested prefabs from asset store?
     
  31. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    Thanks, Stephen. It is very severe indeed. I guess for now I just have to break the prefab links and avoid the automatic gesture of hitting Apply all the time. :p
     
  32. Neo-Dragon

    Neo-Dragon

    Joined:
    Feb 29, 2016
    Posts:
    17
    Don't do this ^

    I have got a workaround.
    It's a horrible workaround but I found it (the bug) was only affecting the first text object in the prefab.
    Create a new textmeshpro object. Leave it all as the default except change the color to fully transparent (no color). It needs to be enabled.
    Click apply on your prefab.
    You'll have an invisible text object that will get screwed up instead.
     
    reese015 and LeonhardP like this.
  33. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Just fell into this bug after a few hours of looking into it, I found a few things.

    I've posted it as a bug with a simple example project just incase it can help, case 984754

    I've also noticed the same as Neo above, in that it only effects the first TextMeshPro object, so that is a work around.

    Also for me, I had a Canvas Scaler on my Canvas, and it was set to 'Scale with Screen Size', which I had set to 4k (3840x2160). I've noticed that this only caused the above problem for me if the Game Window is set to anything other than the same. So if you make them the same, it doesn't cause it.

    HTHs...
     
  34. Andrew-Garrison

    Andrew-Garrison

    Joined:
    Oct 3, 2012
    Posts:
    19
    Stephan, Thanks for letting us know. Is there any further news on this? Should we just wait until 2018.1?
     
  35. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I just finished a conversation with @phil-Unity who just fixed the issue.

    Expect to see a fix for this in the next or subsequent patch for Unity 2017.3.
     
    GilCat likes this.
  36. Andrew-Garrison

    Andrew-Garrison

    Joined:
    Oct 3, 2012
    Posts:
    19
    That's great news! Thank you!
     
  37. otz20100

    otz20100

    Joined:
    Oct 17, 2016
    Posts:
    13
    Fixed on today's patch? (Patch 2017.3.0p2 - 15 January 2018)

    No fixes in patch notes match with that bug... :/

    Someone tried ?
     
  38. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    I am experiencing the same problem without using textmesh pro. I think it's a recttransform or layout related bug.

    I tried 2017.3.0p2 and it's still broken.
     
  39. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    @phil-Unity Can you tell us the expected patch version which we can see this fix please?
     
  40. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is a RectTransform issue which affects UI components which includes the TextMeshProUGUI component.
     
  41. otz20100

    otz20100

    Joined:
    Oct 17, 2016
    Posts:
    13
    I confirm too, 2017.3.0p2, and still here.

    Hold on Unity Team, and please, inform us as soon as possible ! Thanks! ;)
     
  42. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Also tried Unity 2018.1.0b2 with the same results.
     
  43. Dizzy-Jump

    Dizzy-Jump

    Joined:
    Oct 9, 2014
    Posts:
    12
    have the same issue without TMP object. RectTransform on some UI object change randomly every time then i save any prefab :( but with TMP objects it much more annoying
     
    Last edited: Jan 16, 2018
  44. tarmo-jussila

    tarmo-jussila

    Joined:
    Jun 4, 2015
    Posts:
    42
    Is there any estimate when this will be patched?
     
    Foriero likes this.
  45. AdamWaters

    AdamWaters

    Joined:
    Aug 30, 2011
    Posts:
    94
    I just wanted to drop in and say this issue is wildly frustrating. My RPG menus were a huge pain to reconstruct and right now we're limited to a single scene because I can't use a prefab.

    I did discover a work around for anyone that wants to use it. Instead of setting the UI active/inactive, you can change the parent of a given UI to something that is not a Canvas. This seems to hold the position of all child elements. It does introduce a few other complications, but if you're against the wall it's something.

    Any updates on the issue would be greatly appreciated.
     
  46. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Having the same issue, really frustrating. Any news?
     
  47. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    OMG OMG OMG!!!! Are you kidding me UNTY TEAM?

    *** Please notice that this is not a TextMeshPro bug. This is a general editor bug which TMP is being affected as all other editor features do. ***

    I just installed 2017.3.0p3. (Patch 3) and it's still NOT fixed!!!

    This bug was introduced in 2017.2 or one of it's patches. It's been MONTHS!!!! This is a critical engine feature we are talking about. This is not a minor bug. WHAT THE FUDGE!!! ????

    Please just give us a version number which this will be FIXED in!!!!

    It's said that @phil-Unity has fixed this bug but we still don't see it in patch 3 version.
     
    Last edited: Jan 21, 2018
    bartofzo, Dizzy-Jump and GilCat like this.
  48. AntonVikharev

    AntonVikharev

    Joined:
    Jan 17, 2017
    Posts:
    3
    Might be helpful to fix it:

    I found that the issue happens for the first TextMesh Pro UGUI in hierarchy when parent Canvas has enabled Canvas Scaler component set into "Scale With Screen Size" mode. If Canvas Scaler is disabled or in different scaling mode, then the problem does not happen. If TextMesh Pro UGUI component disabled, it happens anyway. If game object with TextMesh Pro UGUI component is disabled, then it skips it and applies the position change to the next one TextMesh Pro UGUI in hierarchy.

    In the case if text go is a child of canvas and has center-middle anchors setup, then its local positions in RectTransform (Pos X, Pos Y) are set to 0 0 0.

    Editor version is 2017.3.0p2
     
    Last edited: Jan 23, 2018
    galactiform_joshua and GilCat like this.
  49. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    It is just sad that this bug keeps going version after version :(
    It is tiresome...
     
  50. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    At this point, the bug is starting to feel as if it is a normal limitation of unity 'No UI', rather than just a bug. that's how long it has been. just downloaded the new 2018.1.0b3 beta (0b4 download doesn't work) and the bug is still here. I cannot develop a game when one of the core engine features isn't working. Please fix this.