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 DaniloCaldeira · Jun 13, 2019 at 02:23 AM · editor-scriptingeditorwindoweditorguilayout

Custom editor window stopped showing up

Greetings.

Yesterday I created a custom window for the editor that featured literally one button. Here's the code (obviously edited for brevity):

 public class CubeSpawner : EditorWindow
 {

    [MenuItem ("Window/CubeSpawner")]

    static void Create() {
        // ... does some stuff...
    }


     public static void  ShowWindow () {
         EditorWindow.GetWindow<CubeSpawner>("CubeSpawner");
     }
 
     void OnGUI () {

         if(GUILayout.Button("Generate")) {
             Create();
         }

     }

 }


It was working, was dockable, and it showed the intended button, up until less than an hour ago, when I took a break, saved my project and closed Unity. I didn't even restart my PC but, when I reopened Unity, the editor gave me some vague warning regarding layouts, and now this custom window only shows up in the Window tab, but when I click it, instead of a window with the declared button showing up, it just executes the functionality implemented in the Create() function. No dockable tab shows up, and it's not available under the "Add Tab" dropdown menu.
Has anyone else experienced this?
Currently using 2019.1, if that helps.

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

1 Reply

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

Answer by Bunny83 · Jun 13, 2019 at 07:52 AM

You attached the MenuItem attribute to your Create method, not to your ShowWindow method. It should be

 // [ ... ]
 {
     [MenuItem ("Window/CubeSpawner")]
     public static void  ShowWindow () {
         EditorWindow.GetWindow<CubeSpawner>("CubeSpawner");
     }
 
     static void Create() {
         // ... does some stuff...
     }
     // [ ... ]

Attributes always belong to the thing that follows the attribute. This is true for all kinds of attributes. Attributes can be attached to all sorts of things. For example the In / Out attribute can be attached to method parameters like this

 public bool SomeMethod([In, Out] object obj)
 {


In case of methods you can think about it this way:

 [MenuItem ("Window/CubeSpawner")] public static void ShowWindow () {
     EditorWindow.GetWindow<CubeSpawner>("CubeSpawner");
 }
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 DaniloCaldeira · Jun 13, 2019 at 02:20 PM 0
Share

It makes sense, but why was it working, then? I made literally no changes to the code between it working and it not working. And it's not about the closing of the editor either, because I had closed it before and when I booted it up again, it was still working fine.

avatar image Bunny83 DaniloCaldeira · Jun 13, 2019 at 02:29 PM 0
Share

That's not possible. You probably didn't have the "Create" method in the beginning which you later put in between the attribute and the ShowWindow method. You probably opened the window before that change. As long as the window is open you can do any changes to the editor window class.


The $$anonymous$$enuItem attribute tells the Unity editor to create that menu item and associate the click event with the method it is attached to. That's all. Unity certainly won't call any other unrelated method Unity doesn't care about what you actually do inside that method.

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

119 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 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

Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer

How to update a EditorGUILayout Textfield value in realtime? 0 Answers

Drag a non standard unity asset on a custom editor slot 1 Answer

Create a custom editor window with repeating subsection (mockup included) 0 Answers

Positioning a button at the bottom of an editor window 1 Answer


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