UI buttons move incorrectly on different screen sizes

Can someone please help me? I’m having a problem with my UI interface. I’ve tried setting it up with the AutoScale Lite plugin, Auto Anchor, UISizeConstraint and UIAspectRatioConstraint, but nothing seems to work.

I attached 3 screenshots. The first 2 show my UI settings in the Properties panel, and the last one shows how it looks on my phone. I also have the UIAspectRatioConstraint set to 1.

My goal is to make the UI look the same on every device, whether it’s a PC, phone or tablet, with the same size and position. I’ve tried a lot of different things, but nothing has worked so far.

I’d really appreciate any help. Thanks in advance!


Hey, do you want both of those squares to always be the same distance apart in “pixels”? If so, here’s’ how I’d suggest fixing things:

  1. Add a new frame, and set its BackgroundTransparency to 1 (so you don’t see it).

  2. Set the size of the Frame to something big enough to hold both of your squares along one side of it, plus a bit extra, since you wanted a gap, I think. Try offset values of 200 by 200 to start. Both values need to match. So, to be clear, it should look something like this: {0, 200},{0, 200}.

  3. Set the AnchorPoint of the frame to (1, 0.5). Set its position to {1, 0},{0.5, 0}.

  4. Put both of your squares into the Frame, so that the Frame is the parent.

  5. Set the AnchorPoint of the top square to (1, 0). Set its position to {1, -10},{0, 0}. In case this isn’t clear, this is so that the square’s right edge is lined up with 100% of the width of the parent, minus 10 “pixels”. You can try other pixels, but try 10 to start.

  6. Set the AnchorPoint of the other square to (1, 1). Set its position to {1, -10},{1, 0}.

  7. Take a look at the UI elements displayed on the screen. Is there too little of a gap between the two squares? Or too much of a gap between the two squares? Adjust the size of the parent frame until you are happy with it. Make sure you keep both size numbers the same. So, for example, to make the gap smaller, try setting the size of the parent frame to {0, 196},{0, 196}.

  8. Once you are happy with it, add a UIAspectRatioConstraint to the parent Frame. And make sure that the aspect ratio property is set to 1. Nothing should change visibly, but in adding the UIAspectRatioContraint, you are telling Roblox to scale the parent frame by the same amount in the x direction as it scales it in the y direction, so nothing will warp with different screen dimensions. Also, in using offset values instead of scale for your positions, the squares will always be the same number of “pixels” apart from each other, regardless of the device.

I hope this helps. Let me know if you need any more help with this, I’ll be happy to help.

2 Likes

That didn’t help. The layout looks fine on my end, but on phones, tablets, and other devices—basically, on anything other than a PC—it looks larger.

1 Like

Could you please teach me the actual principle behind creating UI—specifically, how to configure it so that the position and size remain consistent across all devices?
I would be very grateful if you could.

1 Like

Could you help me figure out why the lighting in Roblox Studio looks different from the lighting in the actual game?

For example, I set up the lighting in Studio and everything looks fine and vibrant. However, after publishing the game and joining it, the lighting looks noticeably different — more gray, washed out, and less vibrant than it was in Studio.

What could cause the lighting to look different between Studio and the published game, and how can I make the in-game lighting match what I see in Studio?

I’m sorry the UI isn’t sorted yet. I’ll definitely try and help you get it right. I’m a little busy right now, it might have to wait until tomorrow, if that’s okay.

As far as the lighting goes, I believe Roblox Studio defaults to not showing things to as high a quality as you might see otherwise, because it’s focused on doing other stuff. But I’ll try to help you figure that out too if I can.

2 Likes

My approach to dealing with UI consistency across all devices comes down to one thing. Add an ImageButton to your game (by itself, directly inside of a ScreenGui) and set the ImageButton’s size to {0, 42},{0, 42}. Now test that on your pc. It will be the same size as one of Roblox’s CoreGui buttons along the top left of the screen. Then test your game on your phone, and you will notice that the Roblox buttons and your buttons have shrunk, and they have remained the same size compared to one another! We seemed to have discovered how to adapt to different devices in the same way that Roblox is doing it! This seems like a solid foundation for doing things, in my opinion, so it is where I begin.

To be clear, offset values are these {0, XOffset},{0, YOffset}. And scale values are these {XScale, 0},{YScale, 0}.

  1. I Use offset values for size. For position, it’s more of a case-by-case basis. Sometimes offset values are more useful, sometimes scale values are.

  2. Using offset values to handle scaling takes care of 2/3 of the device types. Console still seems to not be perfect. It seems too small. So I double the size in those situations. I do that by adding a UIScale to the parent, and leaving its scale value at 1 (we’ll change that in code). Then create a module that looks for IsTenFootInterface() being true, and if it is, then you’re on one of the big screens, and therefore need to bump up the size. Do that by changing the scale property of the UIScale to 2 (get a reference to the specific UIScale object).

Besides that, there are some other things to be aware of:

  • Things you want to keep from warping out of shape, add a UIAspectRatioConstaint, and set it’s aspect ratio to the current dimensions of the object. You can get the aspect ratio by dividing the width by the height.

  • Things you want to display together as a group and want to make sure they never
    overlap and always remain the same relative distance from one another, it’s probably easiest to make sure that they share a parent who has a UIAspectRatioConstraint.

  • Make sure your UI elements are inside of a ScreenGui that has IgnoreGuiInset turned on. This will make sure your calculations of the screen include the ENTIRE screen. Otherwise, a strip along the top will be ignored (the Roblox CoreGui button area).

  • Make sure you understand how AnchorPoints work. And I’d recommend getting in the habit of always dealing with AnchorPoints and Position as a group. AnchorPoints are where you are going to grab onto the object from and place it on the position you’ve decided.

Now, for your exact situation, you seem to not want to have your UI elements change size in the same way that the Roblox CoreGui buttons are changing size, and that’s fine. The way I showed you WILL mean that on a phone, which has a lot less screen space, buttons will appear to be a lot bigger, because there is a lot less empty space surrounding them. So, if you want your boxes to take up a consistent percentage of the screen, then you will have to use scale values:

  1. I’d still suggest keeping your boxes in a parent frame, since the elements go together.

  2. It looks like you want the boxes to take up about 2/3 of the right side of the screen? So try setting the parent frame’s size to {0.3, 0},{0.3, 0}. And add a UIAspectRatioConstraint to the frame, and leave its aspect ratio at 1.

  3. You can adjust the numbers however you want, obviously, but inside of the parent frame, let’s say you want the top 45% to be one square, a 10% gap, and then the bottom 45% to be the other square.

  4. Set the first square’s size to {0.45, 0},{0.45, 0}. Then set the AnchorPoint to (1, 0). Then set the position to maybe slightly away from the right side of the screen, like before: {1, -10},{0, 0}. This means, 100% of the parent frame’s width, minus 10 pixels. And 0% of the parent frame’s height - so, at the top.

  5. Set the second square’s size to {0.45, 0},{0.45, 0}. The set the AnchorPoint to (1, 1). And set the position to {1, -10},{1, 0}.

  6. Then put both of those squares inside of the parent frame.

Let me know how this turns out!

Oh, and as far as the lighting goes (I assume you read my other response), that’s something I have less experience in, and I’d simply recommend that you continue to test things outside of Studio as you’ve been doing. Don’t rely on how it looks in Studio. There are ways to make them match more closely I believe, but I haven’t tried them myself. Maybe try making a separate post about this and see what responses you get?

1 Like

Why don’t you use a Grid Layout? inside a frame, instead of having both buttons on the outside individually, using a Grid Layout you could place buttons inside and put the Padding in size mode and it should be consistent across all screens.

Or maybe am I missing out and haven’t see in. Btw UIAspectRatioConstraint shouldn’t be a worry for now, remove them till you fix the sizing issue.

2 Likes