Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

DontDestroyOnLoad object appears upon error

Discussion in 'Editor & General Support' started by mycatsarefat369, Aug 9, 2021.

  1. mycatsarefat369

    mycatsarefat369

    Joined:
    Aug 9, 2021
    Posts:
    10
    I have been programming a game on Unity and at some point, one I couldn't remember due to not paying attention, occurred whenever I'd run the project. An object called DontDestroyOnLoad appears whenever I run my project, and I can't pinpoint what caused this. I want to get rid of this occurrence because I know it occurs on the basis of an error, as it's happened before and I had solved it by coincidence. I came to the forums hoping the community has a basic understanding of where this can come from, which will help me narrow it down and get to the core of the issue. I have posted an image of the object showing up in hierarchy.

    Edit: after looking a bit more carefully, I discovered DontDestroyOnLoad is actually a scene.
     

    Attached Files:

    Last edited: Aug 9, 2021
  2. mycatsarefat369

    mycatsarefat369

    Joined:
    Aug 9, 2021
    Posts:
    10
    Basically, what causes the DontDestroyOnLoad scene to appear in a project?
     
    Last edited: Aug 9, 2021
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
  4. mycatsarefat369

    mycatsarefat369

    Joined:
    Aug 9, 2021
    Posts:
    10
    As reference to the image, a scene appears called DontDestroyOnLoad. The link you sent me shows the concept of DontDestroyOnLoad on the user's intention to implement into their project. However, in my case I have no implementation of this tool in my project, yet it appears on its own. Unless the link you sent me is actually a solution on how to prevent this scene from appearing, I have yet to gain any knowledge on how DontDestroyOnLoad arises from unrelated code (which is probably the result of a bug).

    Edit: it's also my fault for not realizing DontDestroyOnLoad is a scene and prior to that setting the title to refer to DontDestroyOnLoad as an object. This resulted in a misunderstanding.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Correct. The fact that it is a transient scene is merely an implementation detail. The act of calling DontDestroyOnLoad actually moves the object into a transient scene by that name.

    In long-ago versions of Unity this change was not visible to you, but now it is.

    This is very useful when you study the hierarchy at runtime and need to reason about your game.
     
  6. mycatsarefat369

    mycatsarefat369

    Joined:
    Aug 9, 2021
    Posts:
    10
    This meaning that DontDestroyOnLoad does not pose a problem to my project and is made visible to help me?
     
    Kurt-Dekker likes this.