I’m trying to create an accordion menu. It’s working nicely with preset content, but it’s not working with dynamic content.
The container is a vertical layout group with 2 text components and a button. The content within is inactive when it’s changed. To open it I make it active, and lerp the height of the container from 0 to it’s preferredHeight.
The trouble is that the preferredHeight value isn’t updating when I change the content. If I change the content but deselect “Preferred Height” in the Layout Element component it is the correct size, but then it doesn’t lerp.
If I manually deselect and reselect “Preferred Height” in the Layout Element component, the preferredHeight value changes. However I can’t seem to figure out how to accomplish the same thing in code.
I’ve tried Layoututility, which seems to be made for just this, but it doesn’t work either.