Unity Community


Results 1 to 4 of 4

  1. Location
    Medellin, Colombia
    Posts
    448

    Game Object visible by camera?

    Forgive me if this is trivial... I need a function to test if a given Game Object is currently visible by the camera.
    Director of Development
    C2 Estudio
    www.c2estudio.com

  2. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    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. Location
    Medellin, Colombia
    Posts
    448
    Thanks that works pretty well, what if I want to test if an object is occluted?
    Seems like the OnBecameVisible and OnBecameInvisible ignore occlusion.
    Director of Development
    C2 Estudio
    www.c2estudio.com

  4. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •