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

A subwindow for the second camera view

Discussion in 'Scripting' started by Kaya, Jan 3, 2011.

  1. Kaya

    Kaya

    Joined:
    Dec 21, 2010
    Posts:
    50
    Some games are able to simultaneously display multipe camera views in one the main game window.

    How to create a subwindow for the second camera view as shown above?

    -Kaya
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Depends on. if it is meant to be a real window then you require unity pro and use render textures.

    if you just want to define a subarea of the screen where it shows, check out the normalized view rect on the camera
     
  3. Kaya

    Kaya

    Joined:
    Dec 21, 2010
    Posts:
    50
    Thank you dreamora.

    I am a beginner and I do have Unity 3.1 Pro.
    Is there a way to render the second camera view into a texture?
     
  4. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Thats exactly what you would do with a RenderTexture yes :)

    You can create one with the create button in the project window and then just assign it to the target texture slot in the camera
     
  6. puppeteer

    puppeteer

    Joined:
    Sep 15, 2010
    Posts:
    1,282
    RenderTexture looks like a powerful tool, but can't this just be done with an extra camera limited to the top right corner of the screen?

    Create another camera. In the inspector take a look at "Normalized View Port Rect", and change the values to this:
    X: 0.7 Y:0.7 W:0.3 H:0.3 This will place the new camera window on the top right of the screen.

    Make sure you remove the component Audio Listener from the new camera, as there should be only one in a scene.

    Correct me if I'm wrong, I'm still a beginner with this Unity stuff :D
     
    RonnyLeib96 likes this.
  7. Kaya

    Kaya

    Joined:
    Dec 21, 2010
    Posts:
    50
    Thank you legend411 for the link.. Ffollowing your link, I've managed to create Render Texture and assigned on to a cube that shows the second camera view. Likewise by assigning the Render Texture to a GUI Texture I can see the secondary camera view at a desired location on the screen.

    Thank you Puppeteer for your message. I couldn't figureout yet how to use "Normalized View Port Rect" to get multiple camera views.I am novice Unity user. I would appreciate if you can elaborate your method.
     
  8. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Just FYI, the effect shown in the screenshot can almost certainly be done using multiple cameras only with no render-to-texture (as Puppeteer suggested). For that particular effect, you would most likely simply need to create a second camera, position and orient it appropriately, set its depth appropriately (to a value higher or lower than that of the depth of the other camera - can't remember which), and then set the normalized viewport rect appropriately (e.g. to something like x=.6, y=.6, w=.4, h=.4).

    I may have missed a detail or two in there, but that should be the basic idea.
     
  9. puppeteer

    puppeteer

    Joined:
    Sep 15, 2010
    Posts:
    1,282
    Here's a Step-By-Step:

    First, Create a camera from the top menu bar by going to > GameObject > Create Other > Camera



    Now click on the newly created camera. A side window should open. This is the inspector, it is specific to each object you click on, so when you click on the camera, a window specific to all the functions in the camera will appear on the side.



    In the inspector take a look at Normalized View Port Rect, and change the values like in the picture. Finally, Disable the audio listener of this new camera ( the check box with a red circle around it ).

    Hope that helped.
     
    BitGamey likes this.
  10. Kaya

    Kaya

    Joined:
    Dec 21, 2010
    Posts:
    50
    Thank you Jesse Anders and Puppeteer.
    Yes, I've followed your suggestions and managed to obtain two overlapping camera views as I was asking in my first message.
    One important trick is the Depth field. My main camera has Depth 0 and my second camera hust have Depth value larger than 0.
    I think RenderTexture is also very interesting function. I would like to tank you all for your help.
     
  11. HsmBoy

    HsmBoy

    Joined:
    Aug 1, 2012
    Posts:
    3
    I did in this way but error:colorSurf->width == depthSurf->width colorSurf->height == depthSurf->height
    assert in file C:/BuildAgent/work/b0bcff80449a48aa/Runtime/GfxDevice/threaded/GfxDeviceClient.cpp Line: 1611)
    why?
     
    Last edited: Aug 3, 2012
  12. Kehos

    Kehos

    Joined:
    Jul 26, 2012
    Posts:
    4
    Thank you a lot, it worked for me!!
     
  13. S.A.Z

    S.A.Z

    Joined:
    Aug 20, 2012
    Posts:
    1
    Hello
    thank you a lot, but if you make a simple project with a small pdf ebook that get very better than now.