Using the Canvas Scaler in Constant Physical Size mode

I’m trying to set up the HUD for my mobile game with buttons that keep to a constant physical size so that for example, a button that is 1.5cm wide on a phone screen will also be 1.5cm wide on a tablet, leaving tablet users with a better view of the game instead of giant buttons.

The problem is that I’m absolutely baffled as to how the Constant Physical Size mode is supposed to work.

  • The default values make everything absolutely huge (more so than the usual enormous canvas size).
  • Setting the CanvasScaler’s Physical Unit to Centimeters and giving my button a width and height of 1.5 gives me buttons that look to be pretty close to 1.5cm on my phone’s screen, but doing so completely breaks the button’s text.
  • Leaving the font size at 40 shows no text and gives the error: “Failed to generate dynamic font texture, because all the needed characters do not fit onto a single texture. Try using less text or a smaller font size.”
  • Setting the font size to 1 shows about 2 letters filling up the whole button.
  • Setting the font size to 0 makes the text about 1/4 of the size it was when set to 1.
  • Font size is an Int so it can’t be anything between 0 and 1.
  • Setting the scale of the text’s RectTransform to 0.1 and the font size to 5 gets the text to about the size I want it, but its completely blocky and pixelated.

I can’t see any other options to play with to get what I want so either I’m completely missing something or Constant Physical Size mode doesn’t actually work. Has anyone actually used it successfully yet?

Try this thread - I faced similar problem and ended with a solution that works for me.

Thanks @Thrawn75. I’ll take a look. I’m currently working with Scale With Screen Size mode.

Perhaps the thing that forced me away from using Constant Physical Size mode is that there is no easy way to design in this mode. You have to constantly build to the device to see the outcome because Unity Editor’s Game View is always going to be using the DPI of your computer’s display rather than the DPI of the target device. The Game View presets only allow you to specify width and height in pixels (adding a DPI field would help) so you’re not going to get at design time what you’ll get at runtime. Here’s an example…

I use a 15" MBP with Retina Display (221 ppi) with a 27" Thunderbolt Display attached (109 ppi). I typically have my Unity Editor on the Thunderbolt display and Mono Develop on the MacBook Pro display, so we’ll just use the 109ppi resolution for this example…

Say I want to target the iPhone 4s (960x640@326ppi). If I setup a preset in the Editor for 960x640 and select Constant Physical Size mode, what I see in the GameView is going to be vastly different than what I see on the iPhone. The way I found to get close to what I’d see is to create a preset for the iPhone 4s that is 321x214. Here’s why: 960/326109 = 320.9815951 and 640/326109 = 213.9877301.

Now let’s say I want to target all iOS devices. Here’s how I’d need to setup our Game View presets for my Thunderbolt Display…

3.5" iPhone: 321x214 (rounded from 320.9815951x213.9877301)
4" iPhone: 380x214 (rounded from 379.8282209x213.9877301)
4.7" iPhone: 446x251 (rounded from 446.0306748x250.7668712)
5.5" iPhone: 522x294 (rounded from 521.8952618x293.5660848)
9.7" iPad: 846x634 (rounded from 845.5757576x634.1818182)
7.9" iPad: 685x514 (rounded from 684.7607362x513.5705521)

So this helped me to get close for graphical elements, button sizes, etc. As mentioned by the OP, font size was pretty tricky and I didn’t get consistent results across devices with my experiments. Thus, I switched to Scale With Screen Size mode. It isn’t perfect, but it is easier to predict the outcome.

I’m hoping Unity will offer a solution with a future update. Until then, I’d say it just isn’t practical to work with constant physical size mode.