Concurrency and editor scripts and the play mode

Update:

I solved the issue and detailed the whole automated smoke test process here:
Answer to Continuous Integration with Unity?


Original post:

This question is related to this one:
Programmatically playing a scene for a single frame

The core issue I want to address is that it seems impossible to stop a running game from a seperate thread. I use an editor script to setup a scene and run it using

EditorApplication.isPlaying = true

  • I manage to signal the end of a frame but I can’t access EditorApplication from a seperate thread (error at runtime). This is normal as with most game engines some things must stay synchronized over the main thread
  • If I try to block the editor script (OnGUI/Update) this results in a deadlock of the whole application
  • If I start the playmode paused and try to do just one step (EditorApplication.Step()) I never get the signal (i.e. yield return new WaitForEndOfFrame(); never returns)

Are there any other ideas to try? Otherwise I will stick to having to run an abitrary number of frames as prescribed in the linked Q&A.

You can’t and shouldn’t access any unity api from another thread. The Unity api only works in the main thread (or the thread that fires your events). You can use threads to do your own stuff but you can’t use the api. The only thing that works so far is Debug.Log() :wink: but i’m not sure if it’s even thread safe