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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to get "Using Resolution" of game view?

Discussion in 'UGUI & TextMesh Pro' started by jgb143, Mar 30, 2016.

  1. jgb143

    jgb143

    Joined:
    Jun 8, 2010
    Posts:
    132
    I would like to read in code, the scaled resolution used in the Game view but can't find how to access it.

    These values here are what I would to get:
    upload_2016-3-30_14-14-48.png

    Thanks.
     
    deus0 likes this.
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jgb143 - Hi, have to tried Screen.width and Screen.height?
     
  3. jgb143

    jgb143

    Joined:
    Jun 8, 2010
    Posts:
    132
    Screen.width and Screen.height return the values you're asking for in the resolution dropdown, not the scaled "using" resolution. So in the example above they would return (1280 x 720) and not (734 x 413) like I want.
     
    deus0 likes this.
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jgb143 - No it doesn't - you circled the on screen white text in Game View -> when you scale the editor screen, if you output these values to console or inspector variables, you'll get these values you see on Game view... ?

    EDIT: I've checked this couple of times earlier, I'm quite sure of this. Did you actually test this. I'm using 5.3.4p1
     
  5. jgb143

    jgb143

    Joined:
    Jun 8, 2010
    Posts:
    132
    upload_2016-3-31_12-29-20.png

    Maybe that's the issue. I'm trying to finish up some projects on version 4. I checked release notes but didn't anything about it.

    EDIT: Nevermind, it seem to be working now. I'm not sure why it wasn't before because but as you can see in the image it definitely wasn't working before. All I did was change Update to LateUpdate, which seemed to be what fixed it, but when I changed to back it was still working.
     
    Last edited: Mar 31, 2016
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jgb143 - To clarify, you set your Game View to 1280x720 (like in your last screen shot), and if you do Debug.Log(Screen.width.ToString()); do you get 1280 instead of some arbitrary value, based on scaling of your viewport? Just asking, because I'm not quite sure what you are trying to explain with this last screen shot image.
     
  7. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jgb143 - How about this;

    Code (csharp):
    1.  
    2. Debug.Log(Camera.main.pixelRect);
    3.  
     
  8. jgb143

    jgb143

    Joined:
    Jun 8, 2010
    Posts:
    132
    For that screenshot, I had Debug.Log(Screen.width + " x " + Screen.height ) in Update with [ExecuteInEditMode] on the class. The only thing ever displayed was 1280x720.

    I was also setting rectTransform.sizeDelta and read that had to be done in LateUpdate so I changed from Update and then the Console started displaying the "Using Resolution" like I was wanting. Strangely, it kept working after changing it back to Update and I haven't seen it incorrect since, so I'm not sure what the problem actually was.

    But it's working now so thanks for your help.
     
  9. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    I wonder, did you Undock the GameView? (Floating) :)