Search Unity

Camera orientation initialisation bug on iOS7 devices with Unity5 - need help

Discussion in 'iOS and tvOS' started by FinalD, Apr 8, 2015.

  1. FinalD


    Apr 4, 2013

    I have come across a really irritating bug and I can't seem to find the cause or a good work around. My app is in landscape mode (landscape mode only in fact) but on iOS7 the unity camera seems to think it's in portrait mode. On an iOS 8 device the same code works perfectly. I am using Unity 5 (not sure if the bug was apparent in 4, only started testing with the ios7 device after upgrade )

    On iOS 7 iPad 3 (wrong):
    _camera.aspect.ToString() = 0.75
    _camera.pixelWidth.ToString() = 1536

    On iOS 8 iPad Air (correct ):
    _camera.aspect.ToString() = 1.333333
    _camera.pixelWidth.ToString() = 2048

    This bug only occurs when I am using the camera in the start function of my UI generation class - if I query the same camera a few frames later it has the correct values. Is it possible the camera hasn't been properly initialised by this point? Is there a way to check/force this?

    This bug is obviously screwing up the positioning of all my UI in a big way, so I need to find a solution or a betterworkaround asap.

    Thanks in advance for any help.
  2. TomGolan


    Sep 4, 2012
    I've seen this too in 5.0.1p3. Camera.main.pixelWidth was ok in both cases the aspect ration was 1.3333 for iOS8 and 0.75 for iOS7. Made stop using those params altogether =\
  3. Alexey


    Unity Technologies

    May 10, 2010
    That sounds like you are querying pixelWidth in Awake/Start. The very first frame is problematic to handle (esp. across different ios versions considering apple changed orientation support completely both in ios6 and then ios8). So, bug report with small repro project (so that wa can nag me about it), but for now or move it to courotine to be delayed to the next frame, or use fake empty "loading scene" (that's quite usual trick on ios to preload things) and switch/load to main one (where you query pixel width in Start) delayed until next frame

    EDIT: totally missed "UPDATE: This bug only occurs when I am using the camera in the start function of my UI generation class", but no harm in repeating, eh? ;-)