# Device simulator vs regular game

Before I found out about the device simulator, I had set up different aspect ratios using the add new item to the different screen resolution dropdown. I then found out about device simulator, but have been working with both just to make sure everything looks correct. However I am having one issue.

On one of my canvases I have a script that just moves the canvas up on the y axis if the aspect ratio is 19:9 or 20:9. In the device simulator when using a phone that I know is 20:9 (I also check using the camera aspect) the canvas looks perfect. However, when I dont use the device simulator, and just the 20:9 aspect ratio that i created, the canvas moves way off of the screen view. So I am wondering, does anyone know if how the device simulator is somehow calculated differently than not using it. Im not sure if maybe the device simulator acts differently because it has the safe area etc.

When I check my canvas position in the inspector, the y value increases by around 120 when using the device simulator, but when I am not, the y value increases by around 500. Does anyone possible know what this could be?

How are you comparing to 19:9 or 20:9? Those are rarely precise anymore, even though they used to be.

For instance the iPhoneX resolution is 2436×1125, which ratio simplifier takes to;

2436 : 1125 = 812 : 375

And that is certainly NOT exact! Try it yourself… it is 812.7224-something to 375

You would want to check a range of ratios, and be sure to do your divisions as floating point.

If you do integers, 19/9 is gonna be exactly 2, just like 20 / 9

Instead, use 19.0f / 9 and 20.0f / 9

I usually try to handle everything within a smaller “Safe” area with AspectRatioFitter, or else I try to have special layouts for “wider than 2” or “narrower than 0.5” for instance.

Anyway, here’s some more relevant scribblings to handle UI:

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

I am currently just using the built in Camera.main.aspect to check the aspect ratio, and comparing that to the aspect ratios im building for. Depending on that it is decided how much the canvas will move.
I have never came across AspectRatioFitter, I will look into that as well as the links. Thanks for those.

And that’s why I asked, “how are you comparing?” Floating point is almost never exact enough for equality.

Floating (float) point imprecision:

Never test floating point (float) quantities for equality / inequality. Here’s why:

https://starmanta.gitbooks.io/unitytipsredux/content/floating-point.html

https://discussions.unity.com/t/851400/4

https://discussions.unity.com/t/843503/4

“Think of [floating point] as JPEG of numbers.” - orionsyndrome on the Unity3D Forums