Setting maximum size for Content Size Fitter

Hi,

I put a content size fitter component to my Text UI element so that the rect grows horizontally when the text is longer. However, I want to give it a maximum width, which means that “you can grow larger when there are more text, but NOT larger than this amount”.

Is there any way I can achieve this behavior?

Thanks a lot.

2 Likes

Same issue here. I wonder why there is no Max size. Apparently “flexible width” sounds like it would be used for that, but t has no effect at all.
EDIT Form e the following lines help as a workaround. But it is not ideal because there are timing issues.

float width = (m_LayoutElement.transform as RectTransform).rect.width;
m_LayoutElement.enabled = width >= m_LayoutElement.preferredWidth;