I’m trying to upgrade from 2020.1.4f1 to 2020.3.4f1 (LTS) and I’m having an issue where some of my dynamically created UI elements are four times larger than they were in the older build. The UI created in the editor is all correctly sized, but I create some UI dynamically from a prefab and size them based on their parent transform’s rect width and height. The result of the parent’s width and height is four times larger, so these UI elements end up rendering four times too large.
Any ideas what could be causing this? How do I adjust for this? I doubt just dividing by 4 is the right answer. Preferably, I’d have a way to adjust the asset so it doesn’t happen, so that I don’t have to find everywhere that is using code like this and fix it.
Ok, so it’s already in the scene? Depending on when you get the width and height and if you’re making changes to it, I usually do a yield in a coroutine till end of frame to get the size after the yield. But I’d have to know more about your setup to know if that is the issue. Right now I’m just guessing based on past experiences.
Ah, nice! In that case, it’s just a timing issue where it hasn’t gotten the size set yet, so by waiting till the end of the frame, it’s finished updating the size and you’re able to grab it at the end of the frame.