Search Unity

InitializeOnLoad happens before Unity window is showing

Discussion in 'Immediate Mode GUI (IMGUI)' started by LazyGoblinCody, Oct 21, 2018.

  1. LazyGoblinCody

    LazyGoblinCody

    Joined:
    Mar 18, 2015
    Posts:
    66
    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:
    1,188
    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. }
     
    CulzeanImmerse likes this.
  3. LazyGoblinCody

    LazyGoblinCody

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