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. Dismiss Notice

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:
    36,127
    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:
    36,127
    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.