banner



How To Test If A Object Is On Camera In Unity

Search Unity

Unity ID

A Unity ID allows y'all to buy and/or subscribe to Unity products and services, store in the Nugget Store and participate in the Unity customs.

  1. I am trying to discover means to optimize a loftier poly CAD file imported as FBX. For reasons I won't get into I am unable to reduce the poly count (roughly 4 million tris, verts!!).

    As an culling I want to explore ways to dynamically hide parts of the imported mesh NOT currently seen by the Main photographic camera. ie I am NOT talking about frustrum culling, which works by default, rather I want to turn an object 'OFF' ie Setactive(false), if that object is subconscious or occluded past some other object.

    Is this possible? Or would the price of checking visibility to the Main Photographic camera nullify whatsoever operation gains thru a reduced Poly count?

    After some googling I wonder if Raycasting is what I need
    http://answers.unity3d.com/questions/15636/how-can-i-check-the-line-of-sight-to-see-if-the-pl.html

    If the post-obit script was put on the Principal camera and I substitute 'player' with the object I am checking>

    1. var rayDirection = player. position - transform. position ;
    2. if (Physics. Raycast (transform. position, rayDirection, hit) ) {
    3. if (hit. transform == role player) {
    4. // enemy tin can see the histrion!
    5. // there is something obstructing the view
    Last edited: Mar 25, 2017
  2. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
  3. Thanks will check those out. Also figured a more efficient style to find the 'root' fabric object of my FBX mesh is to tag them, and then in my First method populate an Assortment or listing with these objects using FindGameObjectsWithTag
  4. Unfortunately my mesh is Dynamic ao AFAIK cannot use Apoplexy culling.
    OnBecameInvisible
    https://docs.unity3d.com/ScriptReference/Renderer.OnBecameInvisible.html
    is interesting only disruptive.
    Subsequently reading this thread https://forum.unity3d.com/threads/are-onbecamevisible-and-onbecameinvisible-named-poorly.34225/
    I assume that OnBecameInvisible Only gets called in the editor if your Scene view tab is airtight AND the gameObject in question is leaving the Chief Camera's frustrum.
    Then just frustrum culling which is enabled past default anyways....

    Only if I understand correctly, it SHOULD piece of work as anticipated if you are deploying to iOS??

  5. vElumi

    vElumi

    Joined:
    Nov 21, 2016
    Posts:
    ii
    OnBecameVisible and OnBecameInvisible piece of work in editor too, they just check for the scene view camera as well equally your "normal" cameras in bureaucracy.

    Then in editor, for instance, OnBecameInvisible is called when the object is not visible neither in scene view, nor past any of your cameras

Source: https://forum.unity.com/threads/check-if-object-is-visible-to-main-camera.462777/

Posted by: boyerwalach84.blogspot.com

0 Response to "How To Test If A Object Is On Camera In Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel