Test Play on Editor

Hi guys!

In my current project I’m trying to make a fast “Test Play” of every level I’ve make so far skipping intro/menus/etc.
All levels are on the same Scene so I need to make some custom editor script to do that.

Every level is in a GameObject with a “LevelScript”, I’ve a “MainScript” that manage the various level and activate them when I need.

What I’ve done so far:
I’ve a “Test Play” button on my custom inspector of my “LevelScript”:

if(GUILayout.Button("TEST LEVEL")) {
    EditorApplication.isPlaying = true;
    MainScript.TestPlay(myScript.gameObject);
}

When I press it, the application start playing in the editor and I trigger a function in my “MainScript”:

public void TestPlay(GameObject level) {
    testLevel = level;
    testPlay = true;
}

Setting these variables, on the Start function of the MainScript, I tell it to start the game from that Level skipping intro/menus/etc.

My problem now is that I can’t get to reset those variables when I quit playing!
After I press my “TEST LEVEL”, try the level and then quit, if I play again pressing the standard Play button in the editor, the game start like I’ve pressed “TEST LEVEL” because the “testLevel” and the “testPlay” variables aren’t resetted!

In the end, my two question:

  • how can I reset these two variables ( testLevel=null / testPlay=false ) when I exit from play mode?
  • if the first one isn’t possibile, how can I do what I want to do?

Thanks everyone! I hope everything is clear! :slight_smile:

cool! didn’t know you can do that :smile:

to answer your questions: Create a game object when running in test mode and attach a script to it which has a Method OnApplicationQuit(). There you can reset the stuff.

I’ve already tried that but it isn’t saved in the editor!

void OnApplicationQuit() {
    Debug.Log ("Quitting");
    testLevel = null;
    testPlay = false;
    UnityEditor.EditorUtility.SetDirty(this);
}

I get the “Quitting” message in the console but the values aren’t saved!
It’s like when you change a variable value in Play Mode and it isn’t saved when you stop!

I’ve tried the “SetDirty” because it’s the function I must use in my editor script to save the variables changes. With our without it, it doesn’t change… :confused: