Author Topic: Multiple cameras, UI is rendering in wrong camera  (Read 2532 times)

bagomints

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Multiple cameras, UI is rendering in wrong camera
« on: August 26, 2014, 03:14:01 PM »
Hey,

I have multiple panels that take care of different things, like 1 panel for scrolling combat text, another for character portraits, etc.

I'm using NGUITools.AddChild to instantiate and parent the UI elements to a container in the appropriate panel.

Like the scrolling combat text elements gets added to a container object in the scrolling combat panel.

They get added to the appropriate container object in the panel, but when I go to check the panel's camera, I see that they're not being rendered by that camera, they're using another camera.

But I have a 3rd panel that NGUITools.AddChild to a parent object in that panel, and they're actually rendered with that panel's camera.

So I'm confused why 1 panel is using its camera and another isn't.


EDIT: I found the issue :

NGUITools.FindCameraForLayer(gameObject.layer);

I used this code to get the camera that belongs to the UI element, and it's getting the first camera, which was the WRONG panel I needed.

A quick fix is just to change the layer of each UI element so they get rendered at the appropriate panels since each panel will have a camera for that layer only, etc.
« Last Edit: August 26, 2014, 03:33:57 PM by bagomints »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple cameras, UI is rendering in wrong camera
« Reply #1 on: August 27, 2014, 04:21:10 AM »
If you have multiple cameras, they should each have their own layer. You shouldn't have more than one camera being able to see the same layer.