Renderer.isVisible performance hit ?

I use WorldToViewportPoint to disable some function calls for my AI when they are about 50% away from the screen, but it seems slower to check Renderer.isVisible for each object before WorldToViewportPoint than it does to just do WorldToViewportPoint on every object.

I assumed that Renderer.isVisible would be a quicker way to check if something is offscreen than using WorldToViewportPoint and some math but my tests in Editor with about 30 objects doesn’t match my assumptions.

Looking up Renderer.isVisible seems to show that it uses CalculateFrustumPlanes and I guess that is slower than WorldToViewportPoint? So even if I had a million objects to check, isVisible wont be any help?

Is there a faster way to detect on onscreen object?

my game is 2D, Unity 4, multiple cameras sometimes.

Can you just use a collision trigger sphere around the player? Enemies that touch it can use their function calls.

I guess I could use a huge one, but is that going to be faster than WorldToViewportPoint ?

Calling WorldToViewportPoint will be slower because it’s checking every frame. With a trigger, the OnTriggerEnter/Exit event will only occur once when the enemy touches it.

my WorldToViewportPoint is only 5 times a second, but would still be slower than trigger checks I guess because of checking every single object. I assume trigger checking is highly optimised so I will use that and redo some code :wink: