Initialization Delay

using UnityEngine;
using UnityEditor;
using System.Collections;

public class EditorTest : EditorWindow
		string b = null;

		[MenuItem ("Window/TestNull")]
		static void Init ()
				EditorTest editor = (EditorTest)EditorWindow.GetWindow(typeof(EditorTest));

		void OnGUI ()
				if (b != null) {
						Debug.Log ("b is not Null");


This prints “b is not Null” the first time I open the window after a recompile of this script. It does not happen after I close and reopen the window.

if I put Debug.Log(b) I get blanks so b is empty

Where does b ever get set to anything but null?
If I can not rely on initialization on declaration where is the the proper place for initialization?

It seems that if the instance of your EditorWindow is already there, Unity will initialize/deserialize b for you on assembly reload (this happens between EditowWindow contruction and OnEnable).

Mark b with [System.NonSerializable] to stop Unity deserializing that for you.