🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[Unity] Positioning UI based on content that is dynamic?

Started by
4 comments, last by 3dmodelerguy 3 years, 11 months ago

Lets take two examples of a inspector enemy ui element:

Note these are 2 different elements specifically positioned / size for their content

What I am trying to do is be able to have 1 ui element that I can use when inspecting any enemy but have the content dynamically position and resize itself since the content under the Bio and Skill sections can vary from enemy to enemy.

How would I go about accomplishing something like this?

Advertisement

You should look into “LayoutGroup”s, and “ContentSizeFitter". There are multiple different layout-groups for automatically arranging objects horizontally, vertically or in grids; and content-size fitter can be used to determine the size of an element based on their children.

The issue is not arranging them in a layout group but the actual text elements themselves.

For example, I can set the bio text to whatever height I want in the editor however when I run the game, no matter what content I put in there, the height of that element remains the same. The text still be displayed, it just overflows its element and will run over the content below (or would have extra space at the bottom leaving a bigger gap).

Yeah, I think thats what ContentSize-fitter is for. Someone at work made a whatsapp-like menu where chat-bubbles would change their size depending on the text that is in. I could see if I find some details about it, but I think its best you just try to find a tutorial or check the docu for that.

@juliean Yea, I just I just have one or more mis-configured layout groups or content size fitter (I always get confused as to those settings).

I took your advice and just started from scratch with with the help of a basic tutorial explaining the setting a bit better than my understand, was able to achieve the desired results

This topic is closed to new replies.

Advertisement