Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How can I detect PlayModeState changes even when my Editor Window is closed?

Discussion in 'Editor & General Support' started by sankethhegde, Jun 23, 2023.

  1. sankethhegde

    sankethhegde

    Joined:
    Jun 9, 2023
    Posts:
    6
    I have an editor window in which I'm doing certain actions when play mode is entered. However, when this editor window closes, the playModeStateChanged event is no longer caught since the editor window instance doesn't exist anymore. Is there any way I can continue to catch these events, even when the editor window is closed?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,332
    Yes. Try hooking that event up in a ScriptableSingleton<> instance. The window's class can then access the singleton to get the current state (or just use EditorApplication properties).
     
    sankethhegde likes this.
  3. sankethhegde

    sankethhegde

    Joined:
    Jun 9, 2023
    Posts:
    6
    Thank you, this is exactly what I was looking for!