Hi everyone, I am working on a project that requires a UI panel to appear with its children being “visiblebounds” (2d mask attached), “bounds” (scrollable area which contains any of the following components: image, text, video), “scrollbar” which scrolls and an exit button to close the UI panel.
The components are retrieved and added to the UI panel based on which object i’ve clicked
( for example “tag1” has 1 text component and 1 image component and 0 video components, “tag2” has has 2 text components and 0 image components and 0 video components)
after the text component has been instantiated i’ve added text content by loading a .txt file in resources.
the same goes with image and video components but with their respective content.
the issue i’m having is finding a robust way to (by code) have the components fill themselves with content and THEN setting the total height (width is a constant set to the width of “visiblebounds”) of the total number of components as the “bounds” height.
this is so all of the components are nested inside the bounds area and is scrollable with only the content which is currently inside the “visiblebounds” to be visible.
currently the process goes like this:
if the object i select requires 2 text components and none others, the two text prefabs instantiate, both get their respective text from .txt files (both with differing content) and display inside the “bounds” as intended, HOWEVER i have absolutely no idea to get the ACTUAL height of the text so I can use it to calculate the height of “bounds”… i’ve tried .preferredHeight, it kind of works but not really, it gives me a height that is slightly more than the actual height of all the text that fits within the width. not sure why.
i’ve spent far too long scouring through documentation and other forums posts about similar issues, getting preferredheight of textmeshprougui etc etc… and to be honest every time I think about this now my brain slowly starts dismantling. it’s quite discouraging, anyway i digress. thank you for taking the time to read i hope you can help