Search Unity

  1. Unity 2018.3 is now released.
    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. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    300
    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!