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

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

4 Likes

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.

1 Like

+1.
What’s the approach for doing something similar to this;
8719749--1178997--upload_2023-1-10_16-24-33.png
Where we grey out values driven by a LayoutGroup?

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.

It’s quite a good workaround.

Do you know if Odin handles this? Or if any other asset does?

I’m making a script for this, will let you know if it works.

2 Likes

Very much looking forward to seeing what you make.

1 Like

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.

1 Like