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 !
He seems to be saying that he wants some way to tell when his objects leave the view of his main camera, but not in-game; Through the editor.
it works for me (not perfectly, since the events don't always get called from the game camera if the scene view is visible), but it works if you are displaying only the game view Thanks
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.
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);
}
He seems to be saying that he wants some way to tell when his objects leave the view of his main camera, but not in-game; Through the editor.
– anon25104582