- Home /
OnBecameInvisible only running when game stops
I am working on a 2d game where the orthographic camera follows the player. I am attempting to use OnBecameInvisible to destroy objects as they leave the camera's view (yes I know this is inefficient, I am just trying to get it working). However, OnBecameInvisible does not run until I stop the program, no matter how far the camera gets away from the objects. This is the only camera I have, so I was wondering what might be causing this and what checks I can do to identify the problem.
Answer by Eric5h5 · May 30, 2014 at 02:27 AM
You must disable the scene view camera. Close the scene view tab or just make sure it's not being rendered — I have the scene view and profiler as different tabs for the same pane, so if I need camera visibility stuff to work, I switch to the profiler.
Answer by meat5000 · May 27, 2014 at 10:32 PM
Try this instead
http://docs.unity3d.com/ScriptReference/Renderer-isVisible.html
I understand what isVisible does, but I am unclear how this will help me. That being said, what function should I be using it in? I am getting weird results in both Update and FixedUpdate
Its basically the same except you handle by check ins$$anonymous$$d of by function.
On becomes visible, set a flag that it has appeared on screen (To avoid destroying to early). Is it now invisible? Destroy.
I believe you can use this in any function. At least I think so.
Are you testing this in editor? I believe rendering in Scene view counts towards its 'isVisible' status.
I am testing this with the Scene tab and the Game tab side by side and have the same results in both.. What exactly is 'scene view'? Any link I have found to it in the documentation 404's me. Do you mean that my view of everything in the editor counts as visible?
Hi there, Im having the same problem. Im using a simple OnBecameVisible() and OnBecameInvisible() to make the Skinned$$anonymous$$eshRenderer change materials when player is not visible. I only get the Debug.Log for OnBecameVisible() when I play the scene and OnBecameInvisible() ONLY when I stop the scene. Any ideas on why is this happening? Regards,
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Toggle map/Camera [JS] 1 Answer
Camera position changes after shake 1 Answer
Problem vid GuiTexture 0 Answers
How to rotate the camera smoothly for just 1 second? 2 Answers