How to set screen sizes for all devices

I have these 2 scripts I found online to help manage screen sizes:

CameraAnchor.cs (3.9 KB)

ViewportHandler.cs (5.0 KB)

I tried to get it to work, I even followed some YT videos but it somehow does not work for me. has anyone ever used these scripts and how did you get them to work for you?

the problem I’m facing is that when I set a screen size of let’s say 16:9, I then arrange my UI to be correct to screen size and camera view. Still, then when I change to a different screen size like 1920:1080, it gets messed up, I checked my canvas scaler, and it’s set to screen size, the anchors seem ok depending on each UI location, e.g, the joystick is in the bottom left so anchors are all 0. my canvas Is screen space overlay, and that’s it unless I miss something else.

CamerAnchor script is on my game objects that require screen size adjustments.
ViewPortHandler is on my camera and has fixed units to match the screen.

Here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.

I also use this [ICODE]CanvasScalerOrientationDriver[/ICODE] utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.

I kinda of fixed most of my issues with UI now, but there is another issue I’m dealing with, my tilemap is not set correctly on different screen sizes, how can I get my tilemap grid to fit all sizes? and it does not have a canvas to control its aspect.

this is how it’s supposed to look

I managed to solve my issue, all my UI are set correctly to different screen sizes using the scaler and UI position. my tilemap was a bit tricky, so I created a script that changed the tilemap scale according to screen size, and so far it seems to work pretty nicely. now my script detect player device screen size and modify the scale of tilemap and set it to match the screen.