I Believe This Helps A Lot

Hello everybody,

When i was creating my game i encountered a problem that the game always starting from the current scene not from the first scene which is start scene. I really wanted to be able to start the game either from the Start scene or current scene by deciding.

So i made a research on that for a while and i found that this was actually possible. If you wanted to do this but couldnt find how to do, here is the solution:(I’m using Unity 5.5 btw, so I dont know if this is appropriate for older versions, since it uses SeceneManager to mage scenes instead of Application whic is obsolote in Unity5 or above. But im sure there should be workarounds to this)

  • Firstly, go create a new folder called Editor in the assests.
  • Then create a C# script inside of the Editor folder that you have just created.
  • Everything inside of the Editor folder will be running regardless of the current game playing is active or not if the script has UnityEditor namespace in it.
    So just creating a folder and adding a script in it not adding it to a gameObject will still work for our purposes since we will be using UnityEditor classes and methods.
  • Copy and paste this code to your C# script inside the Editor folder.
    https://pastebin.com/RtXHNeX1 (I took the code from YinXiaozhou)
  • The script name can be anything. It doesnt affect the inside class names as it matters for Monobehaviour for UnityEngine.

After pasting it just save it and you are good to go.

Now if you go to Edit menu you will see a new thing called Always Start From Scene 0 that is attached to ctrl + 0 for windows and command + 0 for mac. And whenever you click it or call it from shortcut you will toggle between starting your scene from 0 to current scene.

Btw, for anyone who doesnt know what 0 means, 0 is the first scene that you attached to your build settings so whatever you put in your build settings as a first item the game will start from there.

And this script has 1 more good side. I saw lots of other codes to perform this action but none of them offered to go to the current scene in editor after playing mode is stopped. They were all getting me to the first scene even after stooping playing, but this code is not changing anything in your open scene and after you stop playing it opens the current scene in editor mode. Whereas all other scripts were using the algorithm of saving the current scene then opening first scene in the editor then starting the game from there. So i found this script veerrryy useful.

This might be a little intermediate thing but if you ever wondered about this, this is it. I didnt go further in this course yet so i dont know if this was already mentioned in the further courses.

If there is anything I wrote wrong in this context please correct me. Even if one people found this useful its enough for me xD

Cheers

1 Like

Privacy & Terms