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

Using Two Cameras, One for UI Overlay & One for World

Discussion in 'UGUI & TextMesh Pro' started by SkillBased, Oct 25, 2016.

  1. SkillBased

    SkillBased

    Joined:
    Aug 11, 2014
    Posts:
    141
    I have a bit of an odd setup in my game currently.

    I have a UI with some canvas objects which basically creates a hud (lives, points, other stats). It is meant to overlay on top of the game world and stay at the top of the screen.

    My current setup uses 2 cameras to make this work.

    I moved the UI GameObject somewhere far away from the objects in my game world (but still in the scene), say at about -40 units.

    I then parented this UI GameObject to a 2nd camera which has "Clear Flags" set to "Don't Clear" so that the colored background becomes transparent.

    Meanwhile the main camera is where you would expect it to be.


    This seems to achieve what I want in keeping the UI outside of the main camera render. In other words, I can postprocess the main camera (say with interesting color effects) and it won't apply those effects to the UI. Also, the UI stays in place as the main camera moves.


    Even though this all seems to work, I don't like how I have the UI as an actual GameObject somewhere in the world. Theoretically you could navigate to that part of the word with the main camera and bump into the UI, in a manner of speaking.

    This seems a bit backwards to me.

    Any suggestions on how I could implement this 2 camera system without being able to travel in the world and "bump into the UI?" (Note: I know I can clamp/restrict the main camera so this never happens, but I'm interested in theoretically, as in not even being able to do that in the editing environment).
     
  2. GTG101

    GTG101

    Joined:
    Feb 1, 2017
    Posts:
    24
    I think all you would need to do is put it on the UI level. You do this using the drop down menu underneath it's name in the inspector.