Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug SceneAssets overwrite each other

Discussion in 'Editor & General Support' started by FOXAcemond, Nov 28, 2020.

  1. FOXAcemond

    FOXAcemond

    Joined:
    Jan 23, 2015
    Posts:
    99
    Hello,

    Today I was trying something different, I have an object in my scene that has a list of scene paths.
    I changed that to a list of SceneAsset and transformed it to paths with AssetDatabase.GetPath in the OnValidate to put in a private array to use in the player.

    The original idea was to keep track of the scenes if they were to be moved or renamed.

    Things got bad, really bad. When I started to rename folders of scenes, some scenes were being replaced by other scenes and their content with it. They were not swapped, but their content were overwritten by the other scene that was now doubled. This, of course, does not happen if there is no reference to the scene assets.

    I don't think this is intended.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    Scenes are unfortunately NOT reference-able in the Unity inspector without a lot of extra shenanigans.

    Google around for "SceneReference" or "SceneField" for some clever editor scripts people have made to work around this annoying limitation, with various degrees of success.
     
  3. FOXAcemond

    FOXAcemond

    Joined:
    Jan 23, 2015
    Posts:
    99
    Yeah given how badly this last experience went, I think I'll stick to manually enter scene paths.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    It really is a shame that the Scene object is a struct, which I believe is part of why it does not play nicely with Unity's serializer (this is purely a theory on my part). I wish you could just drag Scene objects into the inspector... the world would be such a better place!!

    But yeah, I just use strings for scenes. I often make a ScriptableObject that is a list of scenes to load and has a method that I say "Activate Thyself Now!"

    In the load routine, the first scene is loaded by name, which also makes it be the active scene (lighting is taken from here, and instantiated objects go here), then all subsequent scenes in the string array are loaded additively, and then bam, off you go. I try to put all master logic in that base scene.
     
  5. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    Another possibility is to use addressables. With those you can serialize references to scenes and use those to load them.
     
    Kurt-Dekker likes this.
  6. FOXAcemond

    FOXAcemond

    Joined:
    Jan 23, 2015
    Posts:
    99
    Interesting, I'll check that out.