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
1
Question by MattSawrey · Aug 22, 2016 at 09:00 AM · buttoneditorwindowcustom editornodesunresponsive

Custom Editor Window Nodes Unresponsive Button

I'm writing a custom editor window for dialogue trees. That has a series of nodes to represent lines of dialogue.

I want to have a button inside these Node Windows that calls a function. The button is, however, unresponsive and I can't figure out why.

Here's the code from OnGUI in the EditorWindow class that draws all of the nodes (they're in a scroll area):

         GUILayout.BeginVertical();
         {
             scrollPos = GUI.BeginScrollView(new Rect(0f, scrollViewYStartPos, position.width, position.height-110f), scrollPos, new Rect(0, 0, 10000, 10000));
             {
                 BeginWindows();
                 for (int i = 0; i < dialogues.Count; i++)
                     dialogues[i].windowRect = GUILayout.Window(i, dialogues[i].windowRect, DrawNodeWindow, dialogues[i].windowTitle);
                 EndWindows();
             }
             GUI.EndScrollView();
         }
         GUILayout.EndVertical();

The node windows are created within the BeginWindows and EndWindows. The function to create them is:

     private static void DrawNodeWindow(int id)
     {
         dialogues[id].DrawWindow();
     }

And the code in the actual node that defines its display is:

 public virtual void DrawWindow()
 {
         if (GUI.Button(new Rect(windowRect.width - 44f, 1f, 36f, 14f), "Size"))
         {
             ChangeWindowHeight();
         }
 }

^That's the button that isn't responding though. It just seems to get stuck when I press it.

Any help would be appreciated!

Thanks, Matt

Comment
Add comment · Show 1
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 MattSawrey · Aug 22, 2016 at 11:45 AM 0
Share

Alright, I think this question essentially boils down to - How do I get buttons working when those buttons are called inside EditorWindow.BeginWindows; and EditorWindow.EndWindows();?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 22, 2016 at 02:44 PM

Well, first of all you're mixing GUILayout and GUI stuff inproperly. Things inside a GUILayout group should all be "layouted" automatically. So using GUI functions inside a GUILayout group makes no sense.

GUI windows can be a bit tricky. In most cases it's better to use GUI.Window instead of GUILayout.Window. The only difference is that the content of the window can cause the window rect to resize automatically (growth only). Since your window content isn't layouted content you should use GUI.Window

Also your "BeginVertical" makes no sense since there's no layouted content in between BeginVertical and EndVertical. It seems you want to use the normal (manual) GUI system, so you should replace GUILayout.Window with GUI.Window.

This works for me without any problems:

 scrollPos = GUI.BeginScrollView(new Rect(0f, scrollViewYStartPos, position.width, position.height-110f), scrollPos, new Rect(0, 0, 10000, 10000));
 {
     BeginWindows();
     for (int i = 0; i < dialogues.Count; i++)
         dialogues[i].windowRect = GUI.Window(i, dialogues[i].windowRect, DrawNodeWindow, dialogues[i].windowTitle);
     EndWindows();
 }
 GUI.EndScrollView();


If it doesn't work for you it might depend on what you do inside "ChangeWindowHeight();"

If you have trouble understanding how the IMGUI works, have a look at my GUI crash course over here. Maybe if i find the time i could add a few lines about GUI windows as well ^^.

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 · Aug 27, 2016 at 03:46 AM 0
Share

Some kind of feedback would be nice ...

avatar image MattSawrey · Aug 27, 2016 at 10:35 AM 0
Share

I ended up doing this in a different way because I couldn't get the button to work. I know the difference between GUILayout and GUI. That wasn't my issue. It wasn't ChangeWindowHeight() either. The button simply never returned true when pressed.

Thanks for the response though. And that's a good crash course in Unity GUI :).

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

57 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

Related Questions

Custom Editor Button Style like the one in the Hierarchy 0 Answers

Custom HUD Hierarchy in Editor Window 2 Answers

Popup options not changing in custom editor script 0 Answers

Handles.Button unresponsive in custom editor after custom asset serialization 2 Answers

How to trigger button press on a button in an editor window by pressing the return key ? 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