Hi,
I am trying to create a custom EditorWindow at the start of the game. I want the window to be created without having the user to select if from the ‘window’ menu.
I figured out I should use [InitializeOnLoad] - http://docs.unity3d.com/Documentation/Manual/RunningEditorCodeOnLaunch.html, and create the window in the static constructor.
Here is my code:
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class SupportScript : EditorWindow {
static EditorWindow window;
static SupportScript()
{
window = ScriptableObject.CreateInstance(typeof(SupportScript) ) as EditorWindow;
window.Show();
Debug.Log("Window showed");
}
void OnGUI()
{
....
}
}
When I launch the game, I get bunch of errors such as:
-
Instance of ContainerWindow couldn’t be created because there is no script with that name.
-
System.NullReferenceException: Object reference not set to an instance of an object
-
Failed to destroy editor windows: #1
The first error is in the line: Window.Show();
But, if I am changing something in the script (or any other script) and so the scripts recompile, everything works fine. So the problem is only on the first launch.
Does any one know any other method to create a window on editor launch? I would appreciate any kind of help in this issue.
Many thanks in advance,
Anton