Would be nice to be able to generate _autoBuild_SceneIndicesByGuid without build

Issue #1 resolved
Николай Плеханов created an issue

What do you think about it? Are there any objections against from, for example, menu button to regenerate this asset?

Comments (3)

  1. Alfish repo owner

    Well, I guess it depends. Can you explain your use case a little more?

    This asset is an instance of the singleton class SceneReferences (plural). Since it’s a singleton, I need to ensure there’s only one instance of this type in the project. The asset file is meant to be read-only, and not duplicable by the user. I auto-delete it on build because I never thought of a valid use case for keeping it for other purposes. That’s because the only info in the asset is an array that’s easily obtained through other methods.

    Editor code: You can get the array of GUIDs by build-index the same way it’s done in that SceneReferences class:

    var sceneGuids = Array.ConvertAll(UnityEditor.EditorBuildSettings.scenes, s => s.guid.ToString());
    

    Runtime / play mode code: call the SceneReferences.instance property to get/create the object (doesn’t persist the asset file).

    Inspector usage: If you’re just wondering what the GUIDs are, it’s the same ones in the .unity.meta files. I don’t generate them.
    If what you want is just an easy way to see those GUIDs in the editor, or a clickable list of scenes, I guess I could make an inspector code to list them in an asset inside the package’s folder, maybe SceneReferencesEditorHelper.asset. You’d just have to select that read-only asset to see the info in the inspector. But I don’t see much utility for this.

    If you need to use this asset in editor code, I don’t necessarily have objections against it, but I’d need to know what it would be useful for, so I can find a good way to implement it. For example, one way would be putting the (re)-generating code in a separate public static editor method for easy access, with some option to prevent it from being auto-deleted. You’d just have to create your own menu entry or button and call something like SceneReferences.RegenerateAssetFile(...) or similar. But this may not be desired, and it's only useful for advanced users anyways.

    The only thing I don’t want is cluttering the editor with more menu entries (like Assets/Create/… or Tools/…) nor forcing the asset to be visible in user's project, because the plugin should be lightweight and feel as much as possible like a native feature.

  2. Николай Плеханов reporter

    Hi, thanks for detailed answer. Actually, I’ve already developed my own solution (visually the same - convert inspector’s SceneAsset to playmode’s Scene) that fits my project more. Investigation of your sources helped me a lot to deeply understand scene-related asset stuff in Unity. Thank you!

    If you are interesting, I’ve chosen approach when scriptable object with guid-buildIndex relations list is generated by a menu button based on all available scenes (scene list in build settings are ok to edit manually for me) and then used at play-time.

  3. Log in to comment