Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback Why Are Scenes Loaded By Name In The Scene Manager?

Discussion in 'Netcode for GameObjects' started by neon8100, Apr 23, 2024.

  1. neon8100

    neon8100

    Joined:
    Mar 25, 2015
    Posts:
    9
    Pretty much the title here.

    Why on earth in the scene management API are scenes loaded by name and not build index?

    Why does this differ from the normal Scene Management API where calling LoadSceneAsync allows you to reference a scene by build index. You need to pre-define a scene name you want to load and scene names change far more regularly, whereas the build index is far more static/constant.

    This just seems like such a weird choice to me when a paradigm has already been established by the default scene management class. Why offer vastly different input parameters to these methods? Even the example you use in the documentation points out the flaw of using scene names by forcing an editor wrapper to keep it up to date.

    Either way, please add support for passing the build index of a scene into the LoadScene() method of the Network Scene Manager as using scene names is far more cumbersome.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    If you have separate builds for client and server there is no guarantee that the scene build index will be the same. Perhaps this is the reason, or it‘s simply an oversight but then you‘d have to be mindful of that potential pitfall.

    In any case, I use a SceneReference class that lets me assign scenes to Inspector fields and provides me at runtime with the scene name.

    Adding build index support would be straightforward but simply not needed because editor references no longer rely on the scene name thus breaking builds by renaming scenes is no longer an issue. Also I could add a pre-build check to see whether the scene is actually in the build list but NGO already throws a meaningful message when that happens, albeit at runtime.

    Implementation:
    https://github.com/CodeSmile-000001...6517/Runtime/SceneTools/SceneReference.cs#L15

    Note that any MonoBehaviour or SO using this must call OnValidate on each reference from their own OnValidate mehod.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Come to think of it I‘d say using scene index is more brittle and harder to debug than relying on scene names. It‘s easy to overlook the fact that scene 37 is the wrong scene (it may even be a look-alike with only minor progress-based changes) whereas being unable to load „Level 0031“ makes you aware that level numbers are not separated by space (violating naming style).

    And just adding a single extra scene to the build list, perhaps for debugging, shifts all following scene index numbers by +1.

    Of course a reference by GUID like SceneReference trumps over both. ;)
     
  4. neon8100

    neon8100

    Joined:
    Mar 25, 2015
    Posts:
    9
    You make good points and I get why some people might want to use scene names, I'm not really arguing against them. My argument is that the affordances of the method are limited compared to the default scene manager methods -- which not only take scene names, but also has an overload that allows you to pass in build indexes as a parameter.

    Many people will build their games by referencing build indexes because the default scene manager supports this (and it's sometimes easier/faster than using scene names). So folks like myself will build tooling around this -- I have a simple SceneIndex enum that references the build index of any given scene and new scenes just get added to the end of the build list.

    Regardless, I'm all for having multiple approaches to the problem. It's just weird to me that build index isn't presented as an overloaded option inside of the Networked Scene Manager class when it is inside of the default SceneManager. It seems like an oversight to me.