Where can i get the frustrum culling result

Hi Uniphiles

Unity must be doing calculations to determine if something is in the view frustrum or not how can i get the end product of these calculations?

looking to do something like this
Pseudo code
If object is outside camera frustrum
do this
if object is inside frustrum
do that

Thanx

You can try to use Renderer.isVisible

Another option, which is much more reliable in certain situations is to use
Camera.WorldToScreenPoint (position) to determine if a point in the world is in the camera frustum.

Here is some code I wrote for someother purspose to determine if a point is visible in the camera frustrum. I wrote it a long time ago, so don’t judge the code negatively

Vector3 screenPosition = Camera.Main.WorldToScreenPoint (somePosition);

bool isWithinCameraFrustrum = IsVisibleOnScreen(screenPosition);

public static bool IsVisibleOnScreen(Vector3 screenPoint)
   {
     float SCREENWIDTH = Screen.width;
     float SCREEHEIGHT = Screen.height;

     bool outOfBounds_LeftEdgeOfScreen = screenPoint.x < 0.0f ;
     bool outOfBounds_RightEdgeOfScreen = screenPoint.x > SCREENWIDTH;
     bool outOfBounds_LowerEdgeOfScreen = screenPoint.y < 0.0f;
     bool outOfBounds_UpperEdgeOfScreen = screenPoint.y > SCREEHEIGHT;
     bool isBehindPlayer = screenPoint.z < 0.0f;

     bool outOfBounds = isBehindPlayer || outOfBounds_LeftEdgeOfScreen || outOfBounds_RightEdgeOfScreen ||
       outOfBounds_LowerEdgeOfScreen || outOfBounds_UpperEdgeOfScreen;

     return (!outOfBounds);

   }

Ok thx man i will try it out.I would never judge others code I know what mine looks like.
question what is the someposition on line 2? is it a input required or just a name you assigned?

somePosition represents the position you are testing, you are getting the screenspace coordinate of that position and testing to see if it is on the screen with that method. If the resulting value of the WorldToScreenPoint, is coord that is off screen, it means that point in worldspace is not in the camera frustrum.

Yeah, as passerbycmc said, it is just world coordinate.
YOu could just consider the gameobject’s position as the coordinate.
Vector3 somePosition = gameObject.transform.position;
This is the pivot point.

Note that you need to make sure the renderer/mesh is at the pivot point of the gameobject, otherwise the above solution would give you problems. You could have a gameObject at (0,0,0), but the mesh is at (1000,1000,1000), then it would not work.
So, to get more accurate results you should consider using the mesh.bounds.center for the position to test:

http://docs.unity3d.com/ScriptReference/Mesh-bounds.html
http://docs.unity3d.com/ScriptReference/Bounds-center.html

The mesh.bounds.center is the world position of the center of the bounding box which encapsulates the mesh.
This is probably more reliable than the gameObject’s transform position.

I also forgot to mention that using Renderer.isVisible can return false if the mesh is in the frustrum but is being culled by the OC system. SO just because an item is in the frustum of the camera, does not mean isVisible will be true.
Also, an item could be behind the camera, but yet isVIsible is true, because it is required to be rendered for shadows. This is why I don’t like using Renderer.isVisible

i am going to try out the isvisible etc route first not having to do more code seems the way to go especially seen as this is going to be running on hundreds of objects.Long as something isvisible when it should be not to concerned about a few been visible when i rather they weren’t.

OnBecameVisible and its vice versa look like exactly what i need. Thx for the direction