Update Preference Item when Preference menu is closed

Hi!

I am making a preference item that counts total time spent on my project.
Currently I have it working 95%.

The only problem is that, when I don’t have the window open, it doesn’t update.
As soon as I open the preference menu, it updates.

So if I close my project without the preference window open, it doesn’t count the last amount of time spent on the project…

Any suggestions?

You could subscribe to EditorApplication.update to have a function of your code called on every update of the editor application. That way you won’t need an open window.

      EditorApplication.update += CountTime;

      void CountTime() {
          // do something useful here.
      }