Search Unity

Screen.width and Screen.height wrong for iPad in IDE?

Discussion in 'iOS and tvOS' started by sybixsus2, Sep 18, 2010.

  1. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I've got an iPhone project in U3.0 and the game tab screen is set to iPad resolution (1024x768). When I read Screen.width and Screen.height in code - running in the Unity IDE - I get 1192x635. If this is not what I should be using on iPad, where should I get the correct resolution? Or if this *is* where I should be getting the current resolution, how can I get it to report the correct values?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it will get the resolution the game window is set to, whatever that is.
     
  3. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Not sure if it's related, but I have a 13 inch Macbook, and it can't show the iPad's full screen + the Unity IDE stuff. Parts of it get cropped, and Screen.height gives the size of the displayed screen. Pretty annoying. So I always set it to 4:3 instead of the actual resolution, and I check the ratio (width/height == about 4/3) to see if it's an iPad screen.
     
  4. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    It's "set" to "iPad wide - 1024x768". Evidently my monitor allows for more (and less, in respect of the Y axis) but that's the setting I've chosen. How can I force the Window to be the size I've chosen? Even small resolutions like "iPhone small - 480x320" don't work, so whether it's too big or too small, Unity makes up its own mind what the screen size should be instead of using the size I've "set".
     
  5. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    I don't see and iPhone small option in my game screen tab. It has Tall or Wide as the options for the original iPhone resolution.

    Have you mis-quoted? Or is this an indication that something is wrong? Are you running Unity3f1, or an older beta?
     
  6. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I'm running 3f1. Yes, sorry, I did misquote. I'm going back and forth between two machines at the moment, so was going by memory. Which proved to be faulty.

    EDIT: No, the values returned by Screen.width and Screen.height have no bearing on my resolution, the layout, the "set" resolution or anything. I just changed to the "tall" layout, and set to "iPad 1024x768" and my new screen width and height are 1920x20.
     
  7. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    Ok, found the solution to this. I now get the values in Start() instead of including them in the field initializer. Not sure if this is a Windows/Mac issue or a Unity 2.6 / Unity 3.0 issue, but getting the values in the initializer works fine on Unity 2.6 on Windows, but produces random results on 3.0 on MacOS.

    Probably an issue of my expectations rather than a bug, unless anyone disagrees?
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    sure you do it on start not awake?

    If you did it in awake that would be errorous code as awake must not make any assumptions on the rest of the world and should not access anything outside itself either.
    Thats what start is for and out of my experience that has so far worked but I didn't test with f1 yet
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not the case..."Awake is called after all objects are initialized." You can expect the screen to be initialized by the time Awake is called.

    --Eric
     
  10. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I'm doing it in Start, but Awake seems to work as well. I *was* doing it with a field initializer (ie: float SW = Screen.width) and that is the only one which didn't work. That actually seems sensible to me, and I think it was a mistake on my part to have put it there in the first place, but since it worked on Windows, I just assumed that it was ok.
     
  11. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Is the screen smaller at first but then gets "maximized on play"? Because I have noticed that in Start, it will still return the values of the smaller version.