Search Unity

Workaround for layout groups causing prefabs to always be override-able?

Discussion in 'UGUI & TextMesh Pro' started by AcademyOfFetishes, Jun 2, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    I'm told this is a known bug that causes a prefab to always say it can be overriden even when you've just overridden it? " ... it's a known issue in Unity that still isn't fixed in Unity 2019. If a UI element has an auto layout component of some type, such as Horizontal Layout Group or Content Size Fitter, the Rect Transform values in the scene may be slightly different from the prefab due to floating point precision." Is there any workaround to this? It's super annoying
     
  2. IvanIvanovP3

    IvanIvanovP3

    Joined:
    Jan 24, 2021
    Posts:
    6
    This old problem is still valid today, and it does not only arise from floating point precision. The workaround I found is to disable the problematic components (uncheck the enabled checkbox) at design-time and enable them only at run-time (in Awake).
    The same problem sometimes occurs when specifying a camera in Canvas in a prefab, when Canvas itself is a prefab, sometimes when Canvas has pixelPerfect, and in other cases. I created scripts that set problem properties in Awake, and set them to a safe value during design-time.
    Also, this problem occurs if you make the inherited game object invisible in the prefab variant, so I hide it in run-time too, and it helps.
     
    TheVirtualMunk likes this.
  3. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    150
    +1.
    What's the approach for doing something similar to this;
    upload_2023-1-10_16-24-33.png
    Where we grey out values driven by a LayoutGroup?
     
  4. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    518
    The way I see this, as any script that will temper with editor values in editor time, would be for unity to add a checkbox on layout builders to disable autorebuild in editor, when checked out, it should then display a "update layout" button and "update layout and child layout" button. It's hence without breaking change as the default behaviour remains.

    Meanwhile, I think it's once again a job for Odin as it can extend base unity types. Not sure if we can disable editor auto layout rebuilding. If this is the case we need to extend the layouts or copy them in new classes to remove to auto rebuild.
     
    Last edited: Dec 8, 2023
  5. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    518
    It's quite a good workaround.
     
  6. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    206
    Do you know if Odin handles this? Or if any other asset does?
     
  7. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    518
    I'm making a script for this, will let you know if it works.
     
    theforgot3n1 and TheVirtualMunk like this.
  8. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    206
    Very much looking forward to seeing what you make.
     
    Whatever560 likes this.
  9. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    518
    https://gist.github.com/builder-main/680cc14cdaabb1cc2a7ec58992bdad29

    Quick POC. It works for us, however you'll be missing some of our internal classes. I don't have much time to make a standalone version right now, but it should be fairly easy to adapt (I or anyone might adapt it in the gist directly) :

    How to :
    Scene object workflow
    1. Must put in a topmost parent of the roots. (Don't work for roots not in the component children for now)
    2. Add all the layout roots you need (Top most could be enough)
    3. Use Populate button (could be used at runtime be I mostly tested it at editor time). It will disable all content size fitters and layouts while adding them to a list in order to enable/disable them in the UpdateAsync at runtime.
    4. You can fine tune filters if you don't get what you want.
    5. At runtime use the UpdateAsync func and use sequential update checkbox if needed to update your layouts.
    6. Don't use revert variant button

    Prefab variant Workflow :
    1. Same as above
    2. You can use revert variant button in variant prefabs (not the original one !) recursively up, it will revert all things layouts/content fitters temper with, now your prefabs won't be dirtied anymore.

    Final note :
    I had a 10fps increase.
     
    Last edited: Feb 17, 2024
    TheVirtualMunk likes this.