#[SOLVED] Is it possible to let Unity Editor run scene 0 by default On Play?
1 messages · Page 1 of 1 (latest)
ah, thanks for the work around
i take it nothing official then
Not that I know of
thank you
I always assumed that scripts -not- assigned into the execution order run after those that are ?
is this false?
Do it in Awake()
I am, and that is failing
What about it is?
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
How often do you use Awake()?
Why?
what do you mean why 🤨
It really should only be reserved to game handlers
Like the one you're trying to make
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
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)
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
Np, if his solution works for you thats fine, just an alternative way to manage something like this in the editor
thank you
@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");
}
}
[SOLVED] Is it possible to let Unity Editor run scene 0 by default On Play?