- Home /
Executing first scene in build settings when pressing play button in editor?
Hi!,
Is there anyway to execute first scene that has been specified in build settings (the first scene game will load when in production) when I press play button (or whatever short-cut) in unity editor?.
The problem is that I have an startup scene that inits everything before entering the first real scene. This startup scene creates some objects that will live all game and it is a bit of a pain to:
1) Save current editing scene
2) Find startup scene
3) Load startup scene
4) Press play
5) Get to the scene I was editing
This has to be done for every little change I do in a scene in the game. I know steps 4 and 5 can't be avoid obviously, but what about from 1 to 3. Is there anyway to let unity run scenes in the order they appear in the building settings when executing in editor?.
Thanks in advance.
Answer by Paulius-Liekis · Nov 06, 2012 at 09:56 AM
Put this code in menu item (http://docs.unity3d.com/Documentation/ScriptReference/MenuItem.html). Rough code:
EditorPrefs.SetString("lastScene", EditorApplication.currentScene);
EditorApplication.SaveScene();
EditorApplication.LoadScene(EditorBuildSettings.scenes[0]);
EditorApplication.Play();
When play is finished, do this. I'm not entirely sure how to do "When play is finished" part :) Maybe put it on another menu item? :)
EditorApplication.LoadScene(EditorPrefs.GetString("lastScene"));
On the other hand, I found my own solution to this but it was almost the same. Can be checked here:
Answer by Dauphine · Jul 20, 2015 at 10:44 PM
Assuming you don't need to switch back and forth between projects, a simple way to do this is:
File-->Scene Autoload-->Load Master On Play
File-->Scene Autoload-->Select Master Scene (pick the Scene file you always want to jump to when hitting Play).
Your answer
Follow this Question
Related Questions
Determine the Scene that is selected when using context menu 0 Answers
Editor Scene? 1 Answer
How do I iterate over all scene objects from an editor script? 4 Answers
Unity Scene File in Build Question 1 Answer
Unity not responding on opening scenes 0 Answers