remove value from LayoutElement.preferredWidth by script
Hey guys,
I spent quite some time trying to find out myself and searching the net, without any success, so I really need your help...
Under a UI panel with a HorizontalLayoutGroup I have some child components, of which I need to control the width programmatically in certain situations. To achieve this, I have a LayoutElement attached to the children and set the PreferredWidth by script to the required value, which is working fine.
Unfortunately, there are also situations where I need to remove the preferred width, so that the element width is again under full control of the parent's LayoutGroup. How can I achieve this? I couldn't find any method, nor does the float property accept null as value.
Any help is appreciated!
Answer by Reinski · Oct 24, 2015 at 09:55 AM
Lol, it seems I just found the solution myself:
Before, I was only trying to set the value to 0, but setting the value to -1 finally did the trick.
Hope this helps someone in the future who has the same problem. And maybe the according information will find its way into the LayoutElement documentation as well... ;)
You can submit a bug report in Unity and set the type to documentation.
Propose your changes to the documentation there.
Your answer
Follow this Question
Related Questions
Layout Group with Content Fitter? 0 Answers
How to make a Layout Groups child fit its content. 0 Answers
Is there anyway to make an input field stretch to fit a body of text? 0 Answers
Layout groups don't work 1 Answer
Create a Prefab directly inside a GameObject (not SetParent or transform.parent) 0 Answers