- Home /
scale with screen size causes ui objects to ignore boundaries.
I have some prefab objects that are generated from a script. When I have my canvas scaler set to constant pixel size, the fit within the panel they're supposed to. When I set the ui scale mode to scale with screen size, they do not.
Here are two examples of constant pixel size. https://www.evernote.com/l/ATqaVDhaWrlMT78pJzTCz4dVkNB-T4V2dI0B/image.png https://www.evernote.com/l/ATrtLAyMozVIBLbqA9LaKowG6fjwCQGw4jAB/image.png
Here are two examples of scale with screen size. https://www.evernote.com/l/ATpYQFX8A3tNI6z7fPpcEi8p1lQ784qx3DoB/image.png https://www.evernote.com/l/ATqZ3L2bwoRImpSKaG6ouSi4Cv-E5KBhmQMB/image.png
I believe you can tell from these pictures, what the problem is. The other UI objects seem to have no issue with any of the scaling settings. I'm trying to set up my UI so that it can work across many different mobile screen sizes and resolutions.
Answer by Fragmental · Jul 11, 2016 at 11:37 PM
I finally solved this. I needed to add ", false" to my SetParent code. That turns off worldPositionStays.
It change from this
newTodo.transform.SetParent(todoPanel);
to this
newTodo.transform.SetParent(todoPanel, false);
3 weeks of banging my head against a wall and all I needed was a comma and 5 characters :/
Answer by Safforn · Jun 29, 2016 at 09:55 AM
Try setting the screen match mode to Match Width or Height, and the Match value to 0.5.
Now it should match both the height and the width.
But if you can't have your elements to fit your screen perfectly all the time AND match the aspect ratio all the time.
I guess I should have mentioned, I was using $$anonymous$$atch Width or Height with the match value set to 0.5. I also tried other settings and it seemed to make little to no difference.
I currently have the aspect ratio set to 16:9.
Thank you for the response! I finally figured it out. See my answer.