On can I have OnBecameVisible/Invisible ignore the scene/editor camera and only work for the game camera ?

everything is in the title.. I just want to avoid checking if my object is visible in my update function (so every frame) and would like to use unity's OnBecame * functions for that But unfortunately it doesn't work from the editor

any idea ? thanks in advance !

Here’s what I’ve been doing:

void OnBecameVisible()
{
    #if UNITY_EDITOR
    if (Camera.current.name == "SceneCamera") 
        return;
    #endif
    // put your code here
}

I had some similar issues with `AnimateOnlyIfVisible`. You can't watch your object not being animated because at the moment any camera sees it, it will animate. Unfortunately as far as i know there's no way to go around that.

The only thing you can try is not using `OnBecameVisible` but Camera.OnWillRenderObject. `OnWillRenderObject` is a message that is sent by the camera to your object. I'm not sure if this is called camera independently, but as far as i can tell you should be able to sort out which camera is rendering the object. Just check Camera.current if that's your desired camera or not.

I see only one way:

#if UNITY_EDITOR
public void FixedUpdate()
{
if (MyFunctionIsObjectVisible(transform.position))
FireOnBecameVisible();
}
#else
protected void OnBecameVisible()
{
FireOnBecameVisible()
}
#endif

A different solution is just to specify the camera with a tag.
For example:

function Update () {

	if (Camera.current.tag == "MainCamera")

		{

			if (this.GetComponent.<Renderer>().isVisible == false)

				{

					//do something

				}

		}

}

Note that this only works in fullscreen playmode, not minimized view.

This is answer is probably long overdue, but the solution that worked for me was to close the scene view tab.

Unity docs has this to say about OnBecameInvisible:
*

Note that object is considered visible
when it needs to be rendered in the
scene. It might not be actually
visible by any camera, but still need
to be rendered for shadows for
example. Also, when running in the
editor, the scene view cameras will
also cause this function to be called.

Vector3 viewPos = cam.WorldToViewportPoint(objectToCheck.transform.position);
if (viewPos.x >= 0 && viewPos.x <= 1 && viewPos.y >= 0 && viewPos.y <= 1)
{
// Objects that are inside the view frustrum
hasBeenVisible = true;
}
else
{
// Objects that have been inside, but are now outside.
if(hasBeenVisible) Destroy(gameObject);
}