Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple Camera bug on iPhone

Discussion in 'iOS and tvOS' started by mattimus, Apr 26, 2009.

  1. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I've got a scene with two cameras. One for the main camera, and the second for a 3D compass that rotates along the same parent as the main. When I view the setup in the editor, the compass shows up in the bottom right as it should. When I publish to iPhone, it displays in the bottom left. Very strange. Then, jJust for kicks, I shifted the compass to the bottom left corner in editor, and now it shows up in bottom right of the iphone. WTF? Is there some sort of known bug that causes cameras to show up on the wrong part of the screen on iPhone?
     

    Attached Files:

  2. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    Troubleshooting continues with no success.

    To insure it wasn't a wrong setting in that specific project, I started a fresh project with the specific goal of testing multiple cameras on iPhone. I set up a basic scene with a different primitive in each corner of the screen.

    I then put in a second camera and aligned it with the bottom right (cylinder) corner. When running in editor, it remains in he cylinder corner. When I run it on iPhone, however, the camera renders in the cube corner.
     

    Attached Files:

  3. Dark-Table

    Dark-Table

    Joined:
    Nov 25, 2008
    Posts:
    315
    You couldn't really have a more perfectly documented bug. I don't think you're crazy or doing anything wrong.

    I'm going to predict that Monday morning the Unity guys are going to say "please submit a bug with your project attached." Either that or "this has been fixed in 1.0.2."
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    File a bug please, include the project folder. :)
     
  5. blacksp1der

    blacksp1der

    Joined:
    Dec 11, 2007
    Posts:
    76
    the camera viewport rect is broken since unity iphone day one. never fixed.
     
  6. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I found a work-around for now until they fix the bug. Since the viewport rectangle x location seems to be flipped, I detect the current player and shift the rectangle to be in the opposite corner if running on iPhone.


    Code (csharp):
    1. function Start () {
    2.     if (Application.platform == RuntimePlatform.IPhonePlayer)
    3.     {
    4.         //bottom left
    5.         camera.rect = Rect (0, 0, .3, .35);
    6.     }
    7.     else
    8.     {
    9.         //bottom right
    10.         camera.rect = Rect (.7, 0, 1, .35);    
    11.     }
    12. }
     
  7. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    It's not just the x coordinates that are flipped. I've been meaning to write this up since last week and was just about to post a new thread when I noticed your post.

    I've been working with multiple cameras writing to viewports while I've been testing Unity iPhone. I started off working in landscape orientation and this was driving me nuts for a couple of days until I backed off and did up some test cases.

    I'm using two 4x6 grid textures (one for horizontal and one for vertical).

    In a vertically-oriented iPhone application, I can set up a grid of 24 orthogonal cameras (in addition to the Main Camera), point them at a 20x30x1 Cube outside the view of the Main Camera with the texture applied, and get something like this:



    Not so with the landscape orientation, however. Things were...weird.

    To make things simple to explain here, I set up my object, and put four cameras at each corner. The Unity workspace for the vertical version looks like this:



    Within Unity, the landscape version looks fine, but as noted above, cameras that should be on the left show up on the right on the iPhone, but with a twist:



    Did you catch it? On the iPhone, not only is the x-axis swapped, but within the viewport the x-coordinate is swapped again. You don't get a mirror image, as you would if the leftmost coordinate was exchanged for the rightmost and vice versa. What happens is a scrambling of the coordinate system on a per-viewport basis. Each viewport is "right-reading" within the viewport, but the positioning is reversed.

    For most purposes, I suppose this probably won't make any difference, but for something like a puzzle game it would definitely be a problem.
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Is it possible that its related to the device beeing held "heads over" in which case the coordinates are vice versa too.
    What happens if you hold it the other way round?
     
  9. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    Yeah, it's not flipping what is displayed. It is simply mirroring the x position coordinates of the viewing rectangle, presumably working with something like Screen.width - x

    So say you have a camera rect that starts at 0 and is 80 wide. On the iphone, you get (screen.width - 0) which comes out at 480 and the other border at screen.width - 80) which comes out to 400 pixels. Your new camera rectangle is drawn with the new coordinates of 400, 480 instead of 0, 20. It doesn't flip what is drawn within the rectangle, just the coordinates of the rectangle's screen position.
     
  10. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    If you hold it the other way? It looks just the same, only upside down.

    In the photo, the device (a gen 2 iPod touch) is held in Landscape Left mode, with the Home button on the right side. The script used to switch into Landscape mode is shown in the Inspector panel on the right side of the photo.

    Exactly, and it's not doing the same thing in Portrait mode.
     
  11. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    If you hold it the other way? It looks just the same, only upside down.

    In the photo, the device (a gen 2 iPod touch) is held in Landscape Left mode, with the Home button on the right side. The script used to switch into Landscape mode is shown in the Inspector panel on the right side of the photo.
     
  12. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Well that's what we honor as a perfect bugreporter. Thanks. Will you file a bugreport yourself or you'll sacrifice this duty to me? ;-)
     
  13. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    Well, I've lost pretty much time trying to reproduce this bug with the latest beta. Are there any volunteers to submit a reliable project with misplaced second cam?
     
  14. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I can confirm that this does not work properly in 1.0.2.

    Oleg, I can send you my project if you wish.
     
  15. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    That would be nice. Send it please. Looks like me and Rej have used different approach that does not causes bugs.
     
  16. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    Wozik, I'd love to know what approach you used. I'm fully aware that I may be doing something unorthodox in this attached example (I'm just using a trial copy and wasn't sure what the proper bug report process is) but it's easy to reproduce and I can give you the steps if necessary.

    If there's a proper way to do this that obviates the problem, it would be far preferable to designing my game at a 90 degree rotation.

    In some earlier tests, I had problems with viewports in Landscape mode simply not showing up. After about 20 cameras on the screen, some of them just wouldn't render.
     

    Attached Files:

  17. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    Actually, rather than wait for the world to go round again for a reply as to whether steps would be wanted, here they are:

    • Make New Project
      Import PNG for grid
      Create grid Material
      Create Point Light (not essential)
      Create 30Wx20Hx1D Cube at (42.5, 0, 0)
      Apply grid material to Cube
      Rotate Cube on Y so texture is right-reading
      Position Main Camera at (0, 0, -45), make orthogonal with size 10
      Create 4 orthogonal Cameras of size 2.5
      Center Cameras over each of the corner squares on the Cube
      Set each Camera's Viewport Width to 0.1666 and Height to 0.25
      Set Camera Viewport's X and Y to appropriate multiples of width

    And that's it.
     
  18. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    great thanks, I'll see your project a bit later
     
  19. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    darrelplant, you've forgotten to include a scene. Without scene all your cameras got lost.

    We already have a bugreport about this issue, so until fix is released, I think, I will not touch it.
     
  20. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    As I said, I'm a bit of a neophyte with Unity, I thought that a default scene was created with the new project.

    That said, just saving a scene with my test file doesn't seem to solve the problem. I'l try creating a new scene first then building the elements, but saving the existing elements into a new scene doesn't change the outcome at all.
     
  21. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    um, my fault. I wanted to say, that they're lost for anyone trying to explore your submitted project (e.g. me). saving scene - it's the fist task to do then creating project.

    we're working on this bug. I'll post here any news/updates on this
     
  22. darrelplant

    darrelplant

    Joined:
    Dec 19, 2008
    Posts:
    33
    That explains what was going wrong when I tried to open projects from the menu and kept seeing empty scenes. I found that if I quit Unity and dragged the project's .unity file onto the program icon it would open up with the objects visible.

    Great to hear. In the meantime I'm just moving along in a world 90 degrees rotated, which really only impacts me on the GUI since I'm doing a top-down project.

    I have to say, I am really excited by the way things have been going for me with Unity iPhone the past week. I'm starting to feel fairly comfortable with it (although some of the pragma JS scripting stuff is just self-contradictory). I know this feeling will pass the next time I get stuck on something, but I'm close to getting the basic mechanics of my game working after only a couple of weeks.
     
  23. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    This bug just became a show-stopper for my game. While the render data gets flipped, the collision data does not. I'm using ScreenPointToRay to determine when my 3D controls are touched. With the current bug, my controls are (incorrectly) on the left side, but the user has to touch the right side to get things to happen.
     
  24. Wozik

    Wozik

    Joined:
    Apr 10, 2009
    Posts:
    662
    darrelplant, I've experienced same feelings, when I had started with Unity ;-)


    Mattimus, sorry, I just cannot provide any workaround right now. We're struck with FBX importers and other very important issues in the queue. But I've marked camera issue as the next very important thing to work out. So please have a little more patience.
     
  25. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I seem to have found a functioning work-around until this gets fixed. When I cast the ray like normal, the x position seems inverted because the touch on the screen is still registering at the correct, non-flipped location.
    Code (csharp):
    1. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    The solution to this is to deliberately break the ray's x position and flip it along the x axis to match the flipped camera view:
    Code (csharp):
    1. var ray = Camera.main.ScreenPointToRay (Vector2( (1 - Input.mousePosition.x), Input.mousePosition.y)));
     
  26. jerrodputman

    jerrodputman

    Joined:
    Jun 4, 2008
    Posts:
    181
    Did this ever get fixed? I'm trying to do split-screen on iPad, but the input is flipped along the x-axis (e.g., in the editor, the player touches objects on the right side of the screen and it looks correct, but on the device he has to touch the left side of the screen to interact with the right side of the screen).

    Annoying, to say the least.

    edit: If I switch the orientation to LandscapeRight, it seems to work. Still, it should work in all orientations.
     
  27. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    Bump, anyone know if this has been resolved yet?
     
  28. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    According to the bug database, this has been fixed now, so it should work with Unity 3.0.
     
  29. clockworkapps

    clockworkapps

    Joined:
    Jun 23, 2010
    Posts:
    14
    sort of fixed... the graphics appears as expected but for the iphone the coordinates are still reversed. Need to do a (480 - x) to get it to work in landscape mode.
     
    Last edited: Oct 26, 2010
  30. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    LOL, anyone seen if this was properly fixed in the final release of Unity 3?
     
  31. clockworkapps

    clockworkapps

    Joined:
    Jun 23, 2010
    Posts:
    14
    yep all good. They fixed it in one of the betas and it still works in the final!!!