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.

2 Answers

2

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 Match 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.

The whole area of the plane counts as "the edge". So sadly no.

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 :confused:

That's not true. If set to edge, the particles will spawn along the edges and travel in the direction of the normal.