Last active
October 7, 2024 12:27
-
-
Save yasirkula/2a7b5c3a678215a7e819144f63964806 to your computer and use it in GitHub Desktop.
Calculate the time it takes to enter/exit play mode in Unity editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
public class BenchmarkEnterPlayMode | |
{ | |
[InitializeOnLoadMethod] | |
private static void Initialize() | |
{ | |
void OnPlayModeStateChanged( PlayModeStateChange state ) | |
{ | |
if( state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode ) | |
SessionState.SetFloat( "state_exit_time", (float) EditorApplication.timeSinceStartup ); | |
else | |
Debug.Log( state + " in: " + ( (float) EditorApplication.timeSinceStartup - SessionState.GetFloat( "state_exit_time", 0f ) ) ); | |
} | |
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; | |
EditorApplication.playModeStateChanged += OnPlayModeStateChanged; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How To
Simply create a folder called Editor inside your Project window and add this script inside it. Now, every time you enter/exit play mode in the editor, a message will be logged to the Console, showing how long it took to enter/exit play mode.
This is mostly useful to quickly benchmark the effectiveness of different Configurable Enter Play Mode options: https://docs.unity3d.com/Manual/ConfigurableEnterPlayMode.html