Forum begins after the advertisement:


[General] Console Error When Stopping Play

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [General] Console Error When Stopping Play

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #11522
    Xavier Lee
    Level 16
    Keymaster
    Helpful?
    Up
    0
    ::

    Throughout this tutorial series, you may have noticed that sometimes when you stop Play mode, an error message shows up in the console. The error is something along the lines of Some objects were not cleaned up when closing the scene. This happens because Unity GameObjects can be destroyed in three ways: via code using the Destroy() method, unloading a scene, or exiting play mode in the editor. The third is the culprit in this case.

    To fix this error, simply add the following code snippet to the top of any OnDestroy() method.

    if (!gameObject.scene.isLoaded)
    {
        return;
    }

    This piece of code will simply check if the current scene is loaded when OnDestroy() calls, ensuring that the function only runs when the current scene is loaded, and returns if it is not. This should eliminate the error message showing up.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: