Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Game Object visible by camera?

Discussion in 'Editor & General Support' started by ratamorph, Oct 19, 2007.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Forgive me if this is trivial... I need a function to test if a given Game Object is currently visible by the camera.
     
  2. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,525
    There are several ways to do it.

    OnBecameVisible and OnBecameInvisible functions in any script are called when game object becomes visible/invisible to any camera.

    OnWillRenderObject (new in Unity 2.0) is called on any script when object will be rendered this frame for some camera. Inside this function, Camera.current is the camera that will render the object. If object will be rendered by several cameras, OnWillRenderObject will be called multiple times.

    And finally, GeometryUtility class allows you to test visibility manually (by doing bounding box vs. camera frustum intersection test).
     
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thanks that works pretty well, what if I want to test if an object is occluted?
    Seems like the OnBecameVisible and OnBecameInvisible ignore occlusion.
     
  4. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,525
    Unity does not do occlusion culling, i.e. it renders everything in camera's frustum. Of course there's nothing stopping you from doing some sort of occlusion culling yourself, targeted at your specific game.

    But if you want to test occlusion, you'll have to do it yourself somehow. Occlusion is a complex topic though...