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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity UI Prefabs have begun to break / exhibit strange behavior

Discussion in 'UGUI & TextMesh Pro' started by Drowning-Monkeys, Jan 18, 2015.

  1. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    Hi there,

    So this started happening recently. Things that are anchored have started moving around and not being positioned correctly. Difficult to explain so i'll just show you:



    So these are my options sliders. The Sound Effects slider should look like the music slider. The slider is set to value of 1, and it should be anchored over on the right. But the position is wrong, so I adjust the position...



    And everything looks good. I then hit apply, and everything goes back to the way you see it in picture 1! This happens randomly, and in a lot of places. Any thoughts on this one?
     
  2. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    Bump - I really need an answer to this question. Can anything be causing it?
     
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    Sliders are positioned based on their value, its probably just correcting the position.
     
  4. LunaticEdit

    LunaticEdit

    Joined:
    May 1, 2014
    Posts:
    59
    Be VERY careful applying prefabs with Unity UI. It will change it for everything in all of your UIs.
     
  5. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    @LaneFox they don't "break" until applied to the prefab. Note the position that it sets to: -123, the value of the slider is 1, and it is right justified. The value should be 0.

    @LunaticEdit I need it to be a prefab, because this is my UI that gets instantiated in every scene. Not sure how else to do it.
     
  6. BloodyGaah

    BloodyGaah

    Joined:
    May 30, 2013
    Posts:
    1
    I was having the same problem, I got crazy and started to try a lot of things, I guess I solved it by changing all sliders to center and making then childs of the panel behind.

    When it was happening to me, I used to delete and put another one, but every time I tried to prefab, I got this strange error, until it stop happen :)
     
  7. Victor_Kallai

    Victor_Kallai

    Joined:
    Mar 5, 2014
    Posts:
    123
    This is an annoying bug which has been occuring since the first 4.6 beta. With each new version, we were hoping to see it fixed, but we've given up hope, so now we're keeping all of the UI in the scene instead of in prefabs. It's not a fix, but then there's not much else that we can do about it.

    TBH I don't get how stuff like this even makes it past QA, much less past beta stage. This bug has a super high reproducibility rate and it will occur at some point wherever you may be using sliders (like maybe in every Settings menu & HUD ever made.)
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did anyone submit a bug report? If so, post the case number here in case a Unity engineer comes by.
     
    phil-Unity likes this.
  9. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    @Victor_Kallai is it weird that i'm happy that other people are suffering from this problem? I was worried that it was just me. Man I have WAY too many scenes to break the prefabs on all of them.. maybe i'll let it sit there as a bug for now.
     
  10. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    we did just find a bug with 5.0 with prefabs and ordering, its been back ported even though we couldn't repo the same issue in 4.6.X. if you have a bug report that would help us verify
     
  11. hessel_mm

    hessel_mm

    Joined:
    Mar 12, 2014
    Posts:
    44
  12. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    sure, i think QA might just separate them out into different ones at a later time.
     
  14. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
  15. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    If anyone gets this bug - I have a workaround:
    Break the prefab, fix your issue, then create a new prefab (Don't overwrite the old prefab, delete the old one and drag out a new one). Things can definitely break again, but for now that seems to be working for me.
     
  16. doukOmega

    doukOmega

    Joined:
    Dec 31, 2014
    Posts:
    12
    I am having the same issue and i cannot figure out a single way that it may be fixed from our side. It seems that the pivot points and and the anchors positions calculations reset internally when we hit apply to prefab on a parent object of the prefab. Thus that means that we cannot create any single multislider prefab.

    This though is way to much tedious to be done correctly. And if you have nearly 100 ui objects active on your scene at runtime this is not going to happen.

    @Drowning Monkeys this did not work for me. It is just times that works and some others that doesn't.

    For example : If i break the prefab and i create a new prefab from the new modified game objects it seems ok while it exists on the screen. Then when i try to instantiate it sometimes it breaks even in runtime.

    To me the only solution seems to just have a datatype that represents the slider transform and slider utilities. Then create an empty game object at the place that you want the slider to be generated in runtime. While in runtime just create the functionality to replace the empty gameobject with the slider prefab (it seems a bit messy to try adding components and all the children the original ui uinty slider has). Then try to replace the properties with the datatype properties you have stored through a scriptable object.

    Seems like the only solution and it may be a bit of overkill that kind of use of scriptable objects; but i cannot figure out anything else.
     
  17. doukOmega

    doukOmega

    Joined:
    Dec 31, 2014
    Posts:
    12
    Also something that i just found is that the "Handle" gameobject of the "Handle Slide Area" of the "Slider" prefab gets a bit confused when you hit apply to prefab on any parent object or hierarchically higher object of the slider.

    This actually happens or has its Pos X property messed up somehow and it literally changes it to some relative value of the canvas (plus pivot of the parent) to a negative value.

    Moreover this seems like a standard issue i did notice that this is not the case when i disable Raw edit mode on recttrans and when i select Stretch on all the parent objects of the slider.

    Weird enough.
     
  18. Drowning-Monkeys

    Drowning-Monkeys

    Joined:
    Mar 6, 2013
    Posts:
    328
    @doukOmega this worked for me for a day, then broke again... sigh
     
  19. LSPressWorks

    LSPressWorks

    Joined:
    Jun 16, 2014
    Posts:
    25
    So this has been driving me around the bend a few times the last few days.
    A more permanent workaround, since the Devs seem unmotivated to deal with it, is to use an image(UI-> image) instead of a panel. It scales ok, and doesn't break sliders as it goes.
    This is especially a problem for those of us stuck on 4.6x due to the broken joints issues in 5.
     
  20. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    So little time, so much to do. You should cut them some slack.
     
  21. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    I guess that depends on your corporate development philosophy. Some philosophies are, bugs first, new features second. And paying customers tend to expect this.

    Communication matters. The Unity team has a great product/great team/great fan base, and their handling of defects and the community could improve (especially documentation). We all want them to succeed and for it to be easy to use their tools.
     
  22. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Sure, you have very valid points there. Still, there is only so much a bunch of developers can do in a given time frame, so it comes down to prioritizing things. And there will always be things that are "more important" than others.
     
  23. tlt

    tlt

    Joined:
    Nov 16, 2011
    Posts:
    10
    You must set parent of instantiate prefab and you must use
    transform.SetParent(anotherTransform, false)
    instead of transform.parent = anotherTransform or "transform.SetParent(anotherTransform)"
     
  24. Zahidylin_Marat

    Zahidylin_Marat

    Joined:
    Jul 28, 2012
    Posts:
    114
    Also have problems. After some development time - canvas prefab acts strangely. For example - stop responding and dont refresh UI - to make it work i need each time: deactivate prefab, Apply changes, and activate it on scene,