I have an editor script where I want to perform some function after the user finishes ‘playing’ the scene in the editor (using the play button). Is there some way I can have a script that will get a function call or something when the preview has finished playing?
I know I can get whether the editor is currently playing using EditorApplication.isPlaying but what I need to know is when it changes from true to false.
Is there any way to get a function call AFTER the application quit?
– AntonStruykWell, the application quitting is kind of the end of the world. There isn't anything afterwards!
– syclamothIn the editor, I guess you could use EditorApplication.playmodeStateChanged- it's not exactly straightforward, but as far as I can tell, you can handle that. I think it is implemented a bit differently from a usual callback, in that you manually tell it what delegate to call on your scripts.
– syclamothI thought maybe there was some special editor thing for detecting when the user was coming back from previewing the application. I can just poll the EditorApplication.isPlaying in a script that has the ExecuteInEditMode attribute, and use a bool to detect if it's the first time since the game was playing... But if there was something built in I'd rather use that.
– AntonStruykif you make a function in your script called, say, 'OnEditorChangedPlayMode', and then set EditorApplication.playmodeStateChanged to OnEditorChangedPlayMode in your Awake function, as far as I can tell it should then call that function whenever the Editor swaps between one playmode and another. I don't really have any experience with this (other than general delegates work), but you should try it out since as far as I know it's the 'built in thing' you are looking for.
– syclamoth