Search Unity

DontDestroyOnLoad not working?

Discussion in 'Scripting' started by spadin, Sep 27, 2007.

  1. spadin

    spadin

    Joined:
    Aug 13, 2007
    Posts:
    26
    Hi,

    I have an object with many children. I would like for the object and it's children to not be destroyed after I load a new scene, but it doesn't work on a web build.

    It works in the editor, but when I build it as a web player I get at NullException errror.

    Any suggestions?

    Thank you,
    Sandro
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    You should just have to put this on the parent object:
    DontDestroyOnLoad(gameObject);

    It doesn't sound right that it is working in the Editor but not the Webplayer. It works for everyone else, as far as I know, including myself. Are you sure it isn't an error unrelated to DontDestroyOnLoad()?

    You can view the Console log, if you haven't already, by opening /Applications/Utilities/Console.app and choosing File->Open Console Log.

    Cheers,
    -Jon
     
  3. spadin

    spadin

    Joined:
    Aug 13, 2007
    Posts:
    26
    Hi,

    Thanks for your response. Actually, I did open the Console.log, that's how I was able to see that the problem is a NullReference exception. I do agree, it's odd, but it might also have to do with the object being disabled up until the point that it's needed.

    Thank you,
    Sandro