Author Topic: Render UI by game camera  (Read 3595 times)

sheavi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Render UI by game camera
« on: July 08, 2014, 11:58:10 AM »
Hi,

I have a 2D game in which moving elements have UI elements following them. In general, this would not be a problem as it is easy to make UI elements follow a game object using the UIFollowTarget script. The problem is that you can zoom and pan the game camera (this is done by changing its orthographic size and its position). Using the UIFollowTarget script, I get very poor rendering : it seemed as if the UI elements have problems perfectly following the movements of the camera and this resulted in them flickering near the end of their movement.

To solve this problem, I tried having my moving UI elements rendered by my main camera. This way, I don't have to use UIFollowTarget anymore. My setup is this :
- My moving UIPanels are outside of my UIRoot, parented to the game objects they need to follow.
- These moving UI elements are all on the "UI" layer, which is set in the culling mask my main camera. My main camera also have a UICamera script with an event mask set to the "UI" layer.

Everything is working fine with the second approach expect one thing : the scale of my UI panel is completly broken (it is wayyy too small). Is there a way to fix either the first or the second approach? Or is there a better solution to achieve what I want?

Thank you in advance!




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Render UI by game camera
« Reply #1 on: July 08, 2014, 01:13:44 PM »
It's intentionally small. Think about it: a 300x200 widget is 300x200 units in the world. Scaling the panel to a small value ensures that it's of reasonable size instead.

sheavi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Render UI by game camera
« Reply #2 on: July 08, 2014, 01:23:36 PM »
So, you're saying there is no problem using the second approach and having UI elements outside of the UI root that are rendered by the main camera?

As for the first approach, do you have an idea why the UIFollowTarget would have issues rendering perfectly when the game camera is moving?

Thank you very much!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Render UI by game camera
« Reply #3 on: July 08, 2014, 01:37:30 PM »
UIFollowTarget will generally always lag behind by a frame (although you can likely minimize this by cleverly re-arranging your scrip execution order).

Also note that the UI camera must be stationary. It shouldn't move. Make sure it's not a child of your game camera.