1. Home
  2. Knowledge Base
  3. Unity
  4. Enter Play Mode With F5 Key (in Unity)

Enter Play Mode With F5 Key (in Unity)

Symptoms
  • I would like to enter Play Mode with F5 key.
Cause
There is no one-key keyboard shortcut to enter Play Mode and you can not intercept built-in Unity keyboard shortcuts.
Resolution
You can define your own keyboard shortcuts to do what you want. In the sample Editor script below, you can see how to detect the F5 key and enter Play Mode.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;

public class EditorShortCutKeys : ScriptableObject {

    [MenuItem("Edit/Run _F5")] // shortcut key F5 to Play (and exit playmode also)
    static void PlayGame() {
        if (!Application.isPlaying) {
            EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), "", false);
        }
        EditorApplication.ExecuteMenuItem("Edit/Play");
    }

}

To enable this functionality, place this script into Editor folder and then press F5 to enter/exit Play Mode.

 

Was this article helpful?

Related Articles