Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 AlexDavies · Jul 01, 2020 at 02:43 PM · editorguieditor windowuitoolkit

UIElements display:none not working properly

I'm getting some really strange behavior when setting the display-style of a button. The expected behavior is that the install button acts as if it doesn't exist (can be seen at end of gif) - it is invisible and removed from the layout. Setting the style inline or through a style sheet has the expected behavior, but is not dynamic (and is therefore not very useful). My code: C#:

 var installButton = rootVisualElement.Q<Button>("plugin-install-button");
 var removeButton = rootVisualElement.Q<Button>("plugin-remove-button");
 var updateButton = rootVisualElement.Q<Button>("plugin-update-button");
 
 installButton.style.display = pluginInstalled ? DisplayStyle.None : DisplayStyle.Flex;
 removeButton.style.display = pluginInstalled ? DisplayStyle.Flex : DisplayStyle.None;
 updateButton.style.display = pluginInstalled ? DisplayStyle.Flex : DisplayStyle.None;

UXML:

 <engine:Button name="plugin-install-button" text="Install"/>
 <engine:Button name="plugin-update-button" text="Update"/>
 <engine:Button name="plugin-remove-button" text="Remove"/>

First, the button remains visible until I resize the window. The layout is still incorrect even after it dissappears. Calling MarkDirtyRepaint() on either the buttons, their parents, or the root does nothing, and calling EditorWindow.Repaint() also does nothing. The only way that I can get the layout to update correctly is by changing the display property in the UIElements Debugger to 'flex' and then back to 'none'. example gif Note: I'm using Unity 2020.1.0b4

EDIT: I think that my problem may be caused by calling the C# code below from asynchronous code. (I think from another thread). This might be incorrect though, as using VisualElement.schedule to effectively queue actions didn't solve the problem.

Comment
Add comment · Show 7
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 exploringunity · Jul 13, 2020 at 04:53 PM 0
Share

Hey @$$anonymous$$Davies, I don't think there's enough context to solve this issue -- could you share some more code? Is that C# code in your EditorWindow class's OnEnable? You mentioned async/threading?

avatar image AlexDavies · Jul 13, 2020 at 05:30 PM 0
Share

The code is called in a callback method from System.Diagnostics.Process.Start(), or more specifically, in the callback for Process.Exited (which is run when the process has completed its task). In this case the process call is to run some git commands.

The original call to Process.Start is in the EditorWindow’s OnEnable.

avatar image andrew-lukasik · Jul 13, 2020 at 08:50 PM 0
Share

Try running this async code in try/catch block, where catch uses Debug.LogException. You may see hidden exception here.

avatar image AlexDavies · Jul 13, 2020 at 10:19 PM 0
Share

Fortunately (or unfortunately for the future), I no longer have the code for it as I refactored it to not need to change the buttons this way. I think it's unlikely to be an exception, given that it correctly runs the code - the display property does change, it just doesn't seem to trigger a repaint or layout update. It's almost as if it's not detecting the change.

avatar image andrew-lukasik AlexDavies · Jul 13, 2020 at 10:30 PM 0
Share

Unity throws exceptions when foreign thread calls !thread-safe functions,`Repaint` for example

avatar image exploringunity andrew-lukasik · Jul 13, 2020 at 11:20 PM 1
Share

+1 to what @andrew-lukasik said. Here's a $$anonymous$$imal demo -- if you create a basic UIElements editor window and add a simple async call like this...

     public void OnEnable {
 ... // default stuff from Create -> UIElements -> Editor Window
         root.Add(labelWithStyle);
         Task.Run(() => HideLabel(labelWithStyle));
     }
 
     public void HideLabel(Label lbl)
     {
         try
         {
             Debug.Log("Starting sleep.");
             System.Threading.Thread.Sleep(2000);
             Debug.Log("Sleep complete.");
             lbl.style.display = DisplayStyle.None;
         }
         catch (System.Exception e)
         {
             Debug.Log($"{e}");
         }
     }

... you'll get an Exception like so:

An exception was logged that says

If you tried to modify the layout, for example using rootVisualElement.Clear(), you'd get a similar exception -- UnityEngine.UnityException: YGNodeRemoveChild can only be called from the main thread.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Initialising List array for use in a custom Editor 1 Answer

How to make an Editor Window with a border 1 Answer

Text in custom editor is displayed/rendered with boxes around characters... 2 Answers

Is there a way to stylize EditorGUI.ObjectField? 0 Answers

Casting browser window (or any window) inside Unity editor? Or a transparent Unity app? 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