Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Accessing "Display" Option from UI Builder in C#?

Discussion in 'UI Toolkit' started by ATLAS-INTERACTIVE, Jun 16, 2023.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Hi, I'm very new to the newer versions of Unity (as in, I've gone from Unity 5 to 2021...) and I'm trying to build a menu in the UI Builder, but I'm having a few problems showing and collapsing GroupBoxes.

    I've worked out that the Display option under the Display foldout is what I need, but I can't find any available interface for this, at least from Intellisense and the API documentation.

    I've worked out how to get elements by name, but how exactly do I control this Display setting from a script? Is it under a different name?
     
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    To change style values you need to access the through VisualElement's style property. In this case you can use this to show it:
    myElement.style.display = DisplayStyle.Flex;

    And you can use this to hide it:
    myElement.style.display = DisplayStyle.None;
     
  3. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    ah, thank you, spent ages trying to work out how this is done!