Search Unity

Major Bug Found With OnBecameInvisible?

Discussion in 'Editor & General Support' started by Chris-Ramer, Feb 21, 2016.

  1. Chris-Ramer

    Chris-Ramer

    Joined:
    Dec 9, 2015
    Posts:
    45
    In my project, I was attempting to switch scenes when the player was no longer visible by any camera. So I used SceneManagement.SceneManager.LoadScene to load the new scene from within the OnBecameInvisible function.

    Since I was testing my code, I often times would just click the play button while in play mode to quit the game. I would often do this before the player goes off screen. The results nearly ruined my project. I was getting all these Game Over scenes (which is the scene I was trying to switch to when invisible) that were all not loaded. I could not interact with them and there were many duplicates of the same scene.

    I ended up having to close Unity and reopen it to remove the glitched scenes.

    Upon investigation into the matter, I found that objects are considered to be invisible for one frame upon exiting play mode. So what was happening in this case was I was loading a scene as I closed the game, so the next scene never got to be loaded. I think the scenes were glitched from there on out due to being unable to interact with them.

    I don't know if this a glitch or not, but it definitely seems like it to me. If so, let me know and I'll gladly report it. I just don't want to sound dumb by reporting something as a glitch when it is not one. I also don't know if this only happens within the editor. Might occur just by closing the application.

    PS: I am using Unity 5.3.2f1 Personal on Windows 8.1 and am writing in UnityScript.

    Thanks,

    - Chris