Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

InitializeOnLoad happens before Unity window is showing

Discussion in 'Extensions & OnGUI' started by ThatGuyMiniB, Oct 21, 2018.

  1. ThatGuyMiniB

    ThatGuyMiniB

    Joined:
    Mar 18, 2015
    Posts:
    65
    Hey everyone,

    I am trying to create a window that will pop up at the start of opening Unity, but when I open up Unity the window will show for a brief second before Unity opens and then will disappear once Unity does open. I am trying to have it in this order: Unity editor opens and is showing and then the Editor window pops up.

    Thanks in advance!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6.  
    7. public class StartupWindow : EditorWindow {
    8.  
    9.     public Texture m_logo;
    10.  
    11.     [InitializeOnLoadMethod]
    12.     public static void ShowWindow()
    13.     {
    14.         EditorWindow.GetWindow(typeof(StartupWindow),true, "Engine");
    15.     }
    16.  
    17.     private void OnGUI()
    18.     {
    19.         GUI.DrawTexture(new Rect(85,10,240,108), m_logo, ScaleMode.StretchToFill, true, 10.0f);
    20.     }
    21.  
    22. }
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    289
    You could try EditorApplication.delayCall:

    Code (CSharp):
    1. [UnityEditor.InitializeOnLoadMethod]
    2. public static void ShowWindow()
    3. {
    4.     UnityEditor.EditorApplication.delayCall += () =>
    5.     {
    6.         EditorWindow.GetWindow(typeof(StartupWindow), true, "Engine");
    7.     };
    8. }
     
  3. ThatGuyMiniB

    ThatGuyMiniB

    Joined:
    Mar 18, 2015
    Posts:
    65
    This worked perfectly thank you!