Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ShroomWasTaken · Jan 15, 2019 at 03:13 PM · editoreditor-scriptingeditorwindoweditor window

Editor window doesn't open

I'm trying to create a simple editor window but for some reason it won't show up.

Here's my code:

 using UnityEngine;
 using UnityEditor;
 
 public class ExplorerWindow : EditorWindow
 {
     private string m_workdingDirectory = null;
 
     [MenuItem("Window/Explorer Window")]
     public static void ShowWindow() // Gets called
     {
         GetWindow<ExplorerWindow>().Show();
     }
 
     private void Awake() // Never gets called
     {
         Initialize();
     }
 
     private void OnGUI() // Never gets called
     {
         GUILayout.Label("Working directory: " + m_workdingDirectory);
     }
 
     private void Initialize()
     {
         m_workdingDirectory = Application.dataPath;
         Debug.Log("Working directory: " + m_workdingDirectory);
     }
 }
 


The ShowWindow() function gets called when I open the window from the Window/Explorer Window menu, but the window doesn't appear on my screen, and none of the methods like Awake() or OnGUI() gets called.



Edit 0:
I tried creating a fresh new project and copy the code from the one that wasn't working into the new one, which worked. It still doesn't work in my actual project though.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by ShroomWasTaken · Jan 16, 2019 at 10:28 AM

I solved the issue by changing the editor layout to one of the default ones, and then switching back to my custom one. Opening the window started working after doing this.

I also got some weird errors in the console after doing it:

alt text



Doesn't seem like I was doing anything wrong. Maybe the editor layouts in Unity aren't working properly for some reason.


screenshot-1.png (8.9 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jan 16, 2019 at 10:46 AM 1
Share

That probably means that your window was still open somewhere. Note that you can dock an editor window as tab anywhere. $$anonymous$$aybe there was some hidden instance of your editor window somewhere. This can happen when you doing quick experiments and had some logic errors in your editor window.


The problem with GetWindow is that it only opens a new one when there isn't one already. It uses FindObjectOfType to find an existing instance. Also note that you don't have to call Show on the window when using GetWindow. It will show the window automatically.


You can also create an actual new instance of your window by using

 CreateInstance<ExplorerWindow>().Show();

As i said EditorWindows are just ScriptableObjects. So you create them with CreateInstance and can destroy them with DestroyImmediate. Though keep in $$anonymous$$d that using CreateInstance will create a new window every time. So you can have two or more windows open at the same time.

avatar image ShroomWasTaken Bunny83 · Jan 16, 2019 at 02:12 PM 0
Share

I checked if it was tabbed somewhere and I couldn't find it. $$anonymous$$aybe it was positioned off-screen or something. The API for EditorWindow seems to call Show() after using GetWindow(), do you know why they would do that if GetWindow() already shows the window?

avatar image
0

Answer by Bunny83 · Jan 15, 2019 at 03:35 PM

Are you sure that this class is in a file called ExplorerWindow.cs and that this file is located in an "editor" folder?


The EditorWindows base class is just derived from ScriptableObject. Just like any ScriptableObject derived type, the filename and class name has to match. Also since this is an editor class it has to be placed in an editor folder.


Finally make sure you don't have any compiler error in your project. Unity can't compile and load your assemblies if there is an error in any script inside your project.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShroomWasTaken · Jan 15, 2019 at 03:45 PM 0
Share

The file has the same name as the class and it's located directly inside an Editor folder.

Here's a picture of my file hierarchy:


alt text



And I do not have any errors in the project.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers

Set the Rect of PopupWindowContent 1 Answer

SetReplacementShader in Editor Utility? 0 Answers

SearchableEditorWindow 2 Answers

Undo.RecordObject and Constructor of Serializable Class 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges