does anyone know how Unity calculates font sizes on the Text component when the “best fit” option is activated?I’m trying to bring a needle app to multiple devices (Desktop/Tablet/Smartphone) (Landscape/Portrait) and the text should be readable on all devices.
This is what I’m currently doing, but it’s wonky and it would be nice if I can use the text’s parent RectTransform values to calculate the font size.
Hey that is definitely a missing feature overall, currently the screen space UI isn’t practically responsive.
Sadly it seems the “BestFit” implementation in Unity is in C++, so we can’t get a easy glimpse on what is going on there.
I think best would be to let the devs react on this one. Probably could become a feature request.
We’re using three-mesh-ui for runtime UI and that has a best fit implementation. It may not be exposed through our Unity implementation right now but should be able to adjust the settings of underlying objects with code if needed.
The relevant sample ishttps://felixmariotto.github.io/three-mesh-ui/7.x.x/#ex__best_fit
Hi @BMAN to access the underlying threemesh ui objects at the moment you can get hold of them via text.shadowComponent. Where text is a needle text component instance and shadow component is an object of tmui. You might need to iterate its hierarchy then to find the correct object to set the values on.
Furthermore you can of course generate the ui from code as if youd be working with tmui directly - without using the needle engine ui components at all.
It seems like the shadowComponent is the TextElement from tmui, but bestFit needs set on the BlockElement parent of TextElement and I can’t seem to find that
@Marcel_Wiessler1 digging through the engine code it seems like UI elements become either TextElement or BlockElement, but TextElements are not added to a BlockElement
sorry I might need more hand holding if you’re willing - I’ve never worked with tmui before, I’m not sure how I would make a parent BlockElement to a shadowComponent.
Thanks for that link @Marcel_Wiessler1 , this has been a long rabbit hole and it turns out that bestFit was actually working, but their specific implementation for my use case wasn’t noticeable…not sure if you’ve ever looked under that hood but it’s a real head scratcher haha. I’m going to have to create my own. Thanks for your support as always!