Best strategies for not accidently editing whilst still running

It keeps happening to me and i'm sure it must happen to other people, but when i'm previewing something in the editor I keep forgetting to click the play button to stop playback. I then end up performing sometimes lengthy edits that get thrown away when i finally realise i'm still running.

It's exagerrated when using unity remote as you are distracted putting down your iphone.

I was just wondering if there were any sound strategies for trying to avoid this. I can think of a few

  • The GUI changes colour or otherwise makes it obvious that you are still running
  • You have the option to run the game in a read only state so no matter what you try to do with the objects nothing changes and it becomes obvious that you are still running the game. Perhaps alt-clicking the play button allows the current normal running of the game with full editing

Beyond that, which i may suggest to unity. Anyone found a secret to stopping this slightly frustrating thing from happening?

I used to do this all the time too, but I discovered a simple and, in my experience, fail-safe solution:

  • In Unity's menu, go to:
    • (Windows) Edit -> Preferences
    • (Mac) Unity -> Preferences
  • Click the "Colors" button
  • Select "Playmode tint"
  • Change the color from its default (light grey) to a darker more obvious color. (I have mine as RGB: 100,80,80)

Now my UI goes quite dark and red-tinted in colour when in play mode, and there's no mistaking it! I've never accidentally edited in playmode since doing this.

The script that Ashkan linked to can still be useful though, because sometimes you still might want to edit in play mode and save your changes.

Hey guys! There is an editor script here called copy inspector that can help you. It allows you to copy components values while running and paste them when you stopped the game.

This script is written by AngryAnt (Mr. Johansen). He is one of the Unity's staff now. Thank you Mr. Johansen.

If you enable the Maximize on Play button in the Game window, the Game Window will expand when you hit play and get small again when you stop. The downside to this is that you can't see the inspector/hierarchy windows without opening them manually.

I haven't really found any good way around this. Having music playing in your game can help a little, but generally I just try to be careful. I agree that it is very annoying and I've suggested to Unity to have an alternate mode where changes are kept.

Maybe if there were some sort of translucent pop up (just a red highlighted text field and an"!" perhaps)that comes up when you make any kind of an edit whilst in Play mode.

I really liked Duck's strategy of changing the play screen tint ... good one.

There is now an extension available in the asset store, called PlayModePersist

Use a different Window Layout automatically.

This is something I’ve just started experimenting with. In addition to completely solving the problem, you can also have a more useful layout - not just Maximized, but tuned to your needs. For example, in Play Mode I have Game and Scene windows side-by-side, Console below Game, Project/Hierarchy/Inspector below Scene.

To do this, just drop this script PlayModeLayout.cs and change the two layout names to your liking:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
class PlayModeLayout
{
    // Change these to your two layouts
    static string editingLayout = "Wide";
    static string gameplayLayout = "Tall";
    
    static PlayModeLayout()
    {
        EditorApplication.playmodeStateChanged += UpdateLayout;
    }

    static bool last = false;
    
    static void UpdateLayout()
    {
        if (last != EditorApplication.isPlayingOrWillChangePlaymode) {
            last = EditorApplication.isPlayingOrWillChangePlaymode;
            if (EditorApplication.isPlayingOrWillChangePlaymode)
                EditorApplication.ExecuteMenuItem("Window/Layouts/"+gameplayLayout);
            else
                EditorApplication.ExecuteMenuItem("Window/Layouts/"+editingLayout);
        }
    }
}

Only two problems I’ve found so far are:

  • the Scene camera position is saved with the Layout
  • re-layouting is a bit clunky (screen flashes)

I would love to see this be the default behaviour for Unity, and for UT to tune the window layout to be smoother (previously it wasn’t very important since changing layout was a rare action).

I search some information about PlayModePersist.( plug in )
It’s a good solution. Only $10.

Tutorial :

But I have a question …

It still work if I destroy the gameObject after I click the Save button in game ???