Author Topic: My "UI Root" and its child camera are not aligned, I cannot see my UI!  (Read 4548 times)

bkinsey

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 30
    • View Profile
I don't know what happened, but now the pink Plane defining my UI Root and my white special cube representing the Camera's view are not aligned, and I can no longer see my widgets in my game.

Background information, if it helps:
- I'm using a constrained scaling style, 800 x 480 with the Fit option for both content width and content height.
- I made my "UI Root" as a prefab, and create it at runtime
- I have a scene, UIDevelopment, where I want to develop my UI screens and interface. So I work on "UI Root"s children in this scene, and then save the prefab, and test it out in my game scene.
- I didn't notice any misalignment issues until after doing NGUI -> Create -> 3D UI, and it created a "UI Root (3D)" object. I've since deleted it though, since I couldn't figure out how to make 3d UI.

Questions for my understanding:
1. What's the relationship between UI Root->Camera and the scene's MainCamera? Are they the same? Are they supposed to have identical position/orientation at all times, or just that the UI Root->Camera output is displayed on top of the MainCamera output?
2. How can I align the UI Root's panel or the 2D pink rectangle with the UI Root's Camera? The pink rectangle is nowhere inside the white orthographic projection of the camera, and I don't know how to get it inside there, or how it ever got out of there..
3. Why does my UI Root have an odd scaling?  The x/y/z scaling is 0.004166667.  Is this small number something out of the ordinary?
4. Finally, if I have a child GameObject underneath UI root, and modify its x/y/z position, it does absolutely nothing? Shouldn't I be able to modify x and y to move child containers, sprites, labels, etc around?

Example of my setup:

  1. Main Camera
  2. UI Root (UIRoot, UIPanel, Rigidbody, UIEvent Trigger)
  3.     Camera (Camera, UICamera)
  4.     DefaultUI (DefaultUI)
  5.         Button_Gold
  6.             Container (UIWidget, Box Collider, UIButton)
  7.                 Sprite (UISprite)
  8.                 Label (UILabel)
  9.  

With this setup, modifying the position of Button_Gold does absolutely nothing to any children below it. Is this by design?  I am using GameObjects as a grouping mechanism, to organize UI screens in my game and hide/show them as appropriate.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My "UI Root" and its child camera are not aligned, I cannot see my UI!
« Reply #1 on: September 17, 2014, 12:25:29 PM »
1. They are not the same. UIRoot/Camera is used to draw the UI. Main Camera is used to draw your world objects. They're completely different, and often have nothing in common. Make sure that if one camera draws some layer, the other camera doesn't, and vice versa.

2. Reset the position of UI camera to (0, 0, 0). Reset the UIRoot's position to (0, 0, 0). Reset the UI camera's Orthographic Size to 1. Reset the scale of your UI camera to (1, 1, 1). These are all default values.

3. UIRoot is always scaled by 2 / Screen.height by default. 2 / 0.00416667 = 480. Your game view's height is 480.

4. Yes. All I can suggest is double-check what you're doing and make sure you don't have a UIPanel on the same object as a widget. Making a new scene with a layout similar to yours works as expected, and dragging the game object around moves its children.

bkinsey

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 30
    • View Profile
Re: My "UI Root" and its child camera are not aligned, I cannot see my UI!
« Reply #2 on: September 17, 2014, 10:37:30 PM »
Thanks Aren for the information. I didn't want to get blocked, and since I just started out, I just deleted all my objects and started over again.  Now the view is as expected, and I won't touch anything.. haha. (But I understand more, now that you've shared information with me. thanks!)