Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Fixed size canvas in pixels

Discussion in 'UGUI & TextMesh Pro' started by iewufhe, Sep 1, 2014.

  1. iewufhe

    iewufhe

    Joined:
    Aug 2, 2013
    Posts:
    11
    Hi all!
    I try solve one problem with new gui.
    Suppose designer prepared own design to the 1920x1080 screen. And now I need to impose his pretty design exactly pixel by pixel. How to set canvas to fixed size in pixels? It guaranteed that screen resolution will not change for my application. Thus I really will run my app at the 1920x1080 screen computers, not at another 16:9 screens...

    Dilemma: I can't change canvas resolution directly in "Screen space - overlay" and "Screen space - camera" mode! Also I tried so: set canvas child of camera in "World space mode", but I think it's bad idea.

    Any ideas? How does It works in pixels? How I can get really size of element in pixels?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    When in Screen Space Overlay mode, the Canvas will always be the exact size of the screen in pixels. If your game is running 1920x1080, that is the exact size of the canvas, and all your designer's art made for that resolution will be pixel perfect. To me, it seems like there's not actually a problem, if your game is always running at a guaranteed resolution.

    I have a feeling that your real problem is that you are not seeing things this way in the editor? That is, your 'game' window in the Editor is not 1920x1080 (and probably can't be made that big), so everything looks wrong. If this is correct, then your solution will be to add a Reference Resolution component to the canvas. This will make the UI behave as if it's always at 1920x1080, even if the display/window being used is not. It should help your development process of the app.
     
  3. iewufhe

    iewufhe

    Joined:
    Aug 2, 2013
    Posts:
    11
    Yes It is my problem.
    I'm trying do this but it looks like bug(image). White images size is 1080x1080. But screen is 1980x1440
     

    Attached Files:

    • p3.PNG
      p3.PNG
      File size:
      61.8 KB
      Views:
      1,522
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    If you want to force your app to always run at 1920x1080, then that's a thing you do for the entire app, not just for the UI system. You need to take a look into the Screen class, as well as the Player Settings.
     
  5. iewufhe

    iewufhe

    Joined:
    Aug 2, 2013
    Posts:
    11
    No, it's not my problem. I want to develop 1920x1080 screen apps in unity editio but i dont know how set screen to this resolution and how to check whether elements are needed size in pixels.
     
  6. khoowaikeong

    khoowaikeong

    Joined:
    Jun 13, 2013
    Posts:
    18
    yup it seem funny that the editor will use the actually editor game window size to scale the canvas in the editor. and because of the window borders even if you expand it to full, it would have some werid resolution like 1826x1027 and that make creating pixel prefect texture a headache without a higher than 1920x1080 monitor.

    as a compromise i drag the game window out of the editor and fixed it dimension to 960x540. so what ever is the size of the UI i create in the editor, i know i can just 2x the value when i make the texture for it. it not a major issue, it just a pain in the butt that that editor doesn't show you the ratio for a given resolution.