#[SOLVED] Is it possible to let Unity Editor run scene 0 by default On Play?

1 messages · Page 1 of 1 (latest)

silk storm
#

Have an object in every scene that loads 0 upon start

#

Only when you haven't loaded it yet of course

serene galleon
#

ah, thanks for the work around

i take it nothing official then

silk storm
#

Not that I know of

serene galleon
#

thank you

serene galleon
#

I always assumed that scripts -not- assigned into the execution order run after those that are ?
is this false?

silk storm
#

Do it in Awake()

serene galleon
#

I am, and that is failing

silk storm
#

What about it is?

serene galleon
#
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Project.Scenes
{
    public class SceneDefaultSelector : MonoBehaviour
    {
        public static bool firstLoad;

        public void Awake()
        {
            Debug.Log("SceneDefaultSelector ");
            if (firstLoad == false)
            {
                firstLoad = true;

                var scene = SceneManager.GetActiveScene();
                if (scene.buildIndex == 0)
                { return; }


                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }
        }
    }
}

I have added the above script to the execution order

despite this Awake of other scripts not in the execution order are called before it

silk storm
#

How often do you use Awake()?

serene galleon
#

what do you mean

#

i mean there's a lot of scripts that use Awake

silk storm
#

Why?

serene galleon
#

what do you mean why 🤨

silk storm
#

It really should only be reserved to game handlers

#

Like the one you're trying to make

serene galleon
#

i dont understand the discussion

i am expecting scripts in the execution order to run before any other scripts

#

thats not true ofcourse

#

but again outside the point of the discussion

twin sun
#

There are ways to access the scene order if you wanted to use editor scripting, for example:
https://docs.unity3d.com/ScriptReference/EditorApplication.EnterPlaymode.html

Or
https://docs.unity3d.com/ScriptReference/EditorApplication-playModeStateChanged.html

Then you can check
https://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager.html or https://docs.unity3d.com/ScriptReference/EditorBuildSettings-scenes.html to load to your specific scene if your not already on it

You can also do this how you are trying with a mono script, though this way you wouldnt need a script in every scene

#

You could then make an editor window or a Context menu if you wanted to toggle your logic to always switch to scene x or not (in case there are times you want to be testing from the scene your on)

serene galleon
#

His workaround is valid... all i want is to load scene 0 at Play... so when you Stop you return to the scene that was last used

#

thanks for the trouble of linking all these btw

twin sun
#

Np, if his solution works for you thats fine, just an alternative way to manage something like this in the editor

serene galleon
#

thank you

serene galleon
#

@silk storm @twin sun

Don't know if you're interested but this appears to work for me:

Place this in your "Assets/Editor/"

using UnityEditor;
using UnityEditor.SceneManagement;

public class EditorTools
{
    [InitializeOnEnterPlayMode]
    static void OnInitializeOnEnterPlayMode()
    {
        EditorSceneManager.playModeStartScene = AssetDatabase.LoadAssetAtPath<SceneAsset>("Assets/Project/Scenes/StartScene.unity");
    }
}
serene galleon
#

[SOLVED] Is it possible to let Unity Editor run scene 0 by default On Play?