Search Unity

Objects that marked as DontDestroy was destroyed.

Discussion in 'Scripting' started by Airat1995, Jun 25, 2017.

  1. Airat1995

    Airat1995

    Joined:
    Mar 21, 2014
    Posts:
    5
    Hello, I create a game for mobiles. I created some game object like: LevelManager, Canvas and AudioManager. After that I marked them as DontDestroy. Everything works fine when I using Unity remote, but when I compiled game for mobile I saw unexpected results. My camera was destroyed , some buttons don't respond to clicks (more strange to me, that some buttons are clickable and works fine, and some of them not). Is anyone know what the problem is?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    How do you know they are being destroyed? Do you see them missing in play mode on the editor?

    Also, make sure you are properly targetting the right gameobjects to keep them from not being destroyed. And make sure you actually need to keep the objects between scenes.

    Note that don't destroy is designed to carry stuff between scenes so that a scene switch doesn't destroy it.
     
  3. Airat1995

    Airat1995

    Joined:
    Mar 21, 2014
    Posts:
    5
    In the editor mode everything is fine, but when I run the game on phone, camera is not available (try to run a scene without cam and you will understand what I'm talking about).
    Yes, I'm really need to keep my objects between scenes. It helps to me to save time after switching scenes.
     
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
  6. Airat1995

    Airat1995

    Joined:
    Mar 21, 2014
    Posts:
    5
    Thank you for assets. I tried this thing and get more strange output than I expected. I send to log smth like that GameObject.Find("Back").GetComponent<Button>() and got null! But button is clickable and moreover it do what it should to do! I think I totally lost engine's logic...
     
  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Is the button called "Back" and not "back" or "BACK"?

    And you have to make sure the object called "Back" has the button component on it.

    Honestly, it's hard to say what is going on, since I can't see your project.

    I will say that depending on what you are doing with the stuff you are trying to move between scenes, it might be creating more issues than it is solving.