How to prevent Start being called when the application stops?

I know this sounds like nonsense, but my Start method in my Main Monobehaviour class is being called twice in the Editor. Once when I hit Play, and again when I stop.

I think this has something to do with [ExecuteInEditMode] which is heavilly used by 2 components I am using(NGUI and AVPro Video.

Can anyone suggest a workaround?
What should I check for in my Start method for the 2nd time it is called?

Why are you using [ExecuteInEditMode]? Is it only for functionality in some other event function like Update()? If so, you’ll have to explicitly guard code that shouldn’t run in edit mode. I believe this should have the desired affect:

[ExecuteInEditMode]
class SomeComponent : MonoBehaviour
{
    Start()
    {
#if UNITY_EDITOR
        if (UnityEditor.EditorApplication.isPlaying)
#endif
        {
            // code that should only execute during normal play, but not during edit mode
        }
    }
}
1 Like

Just remove execute in edit mode… You normally don’t want editor functionality and gameplay functionality in the same script.

Thanks. Turns out my issue was a socket that wasn’t closed onApplicationQuit