Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using references to destroyonload objects in the editor

Discussion in 'Editor & General Support' started by cephalo2, Mar 19, 2018.

  1. cephalo2

    cephalo2

    Joined:
    Feb 25, 2016
    Posts:
    262
    It is convenient to place game objects into the public fields of monobehaviors in the editor, but it can get complicated when those objects are dontdestroyonload.

    I have a main menu scene and a gameplay scene. The main menu has several dontdestroyonload objects that will destroy any new instances of themselves when the game returns to the main menu scene. It works great, except I can't then put them in fields of any non-destroyonload objects.

    The non-destroyonload objects are expecting a new instance of the ddol objects, and if the scene is reloaded they just end up with a missing target, as the instance they are expecting is destroyed.

    Is there an easy work around to force a field to switch to the original instance instead of always looking for a new one? Or do I have to stop using ddol object to populate fields?