Want a play button that runs from the beginning of the scene

Currently, pressing the play button in the editor will play the currently open scene.

I think that's fine.

However, when I build and run it, it runs from the beginning of the scene in the build settings, so I want a button to play from the beginning of the scene to check it.

Google tells me,

https://answers.unity.com/questions/441246/editor-script-to-make-play-always-jump-to-a-start.html

https://stackoverflow.com/questions/35586103/unity3d-load-a-specific-scene-on-play-mode

Google might tell you more!

@Kurt-Dekker thx comment.

umm...
It's good to make an Editor script, but I want it to be bundled originally.

It takes time to introduce it every time I create a Unity project.
(Especially for beginners)

1 Like

Game development takes time.

Good luck to you!

Since this is now a top result in google, I thought I would share my script for this.

Place it in a folder named Editor and remember to rename PlaymodeTargetScene.

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;

public class PlayFromScene : EditorWindow
{
    private static string PlaymodeTargetScene = "YOUR START-UP SCENE GOES HERE";
    private static string CurrentScene;

    [MenuItem("Developer Tools/Play From Start")]
    private static void PlayFromMainMenu()
    {
        if (EditorApplication.isPlaying) { EditorApplication.isPlaying = false; return; }
        if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } // Save current scene if it has unsaved changes

        // Remember currently active scene
        CurrentScene = SceneManager.GetActiveScene().path;

        // Start playing from the main scene
        if (EditorSceneManager.OpenScene(GetScenePath(PlaymodeTargetScene), OpenSceneMode.Single).IsValid())
        {
            EditorApplication.isPlaying = true;
            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
        }
        else { UnityEngine.Debug.LogError("Scene not found: " + PlaymodeTargetScene); }
    }

    private static void OnPlayModeStateChanged(PlayModeStateChange state)
    {
        if (state == PlayModeStateChange.EnteredEditMode)
        {
            if (!string.IsNullOrEmpty(CurrentScene)) { EditorSceneManager.OpenScene(CurrentScene); }
            EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
        }
    }

    private static string GetScenePath(string sceneName)
    {
        foreach (var scene in EditorBuildSettings.scenes)
        {
            if (scene.path.Contains(sceneName)) { return scene.path; }
        }
        return null;
    }
}

Be warned that the script is not fully functional. For some reason, debug.log and debug.logerror do not work at all (maybe because this is not running off monobehaviour?) and neither does the functionality to return to your previous scene after you exit play mode. If anyone in the future has any fixes, be my guest in posting them.