Search Unity

How do I change the start of visual elements?

Discussion in 'UI Toolkit' started by WizByteGames, May 21, 2019.

  1. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    I wanted to dig in to UI Elements and see if I would like it vs IMGUI, but I don't understand one thing. How do you make visual elements visible or hidden if you have a certain state set.

    For example if I have a menu for stats and one for items. I want to have the visual elements that are associated with stats visible and the ones for items hidden.
     
  2. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    I still haven't gotten an answer, but I think I found a way, but I need to know do you need to create the visual elements in the awake/start methods or can you just call the functions to manipulate them from other functions. Every example I have seen has you setup your UI in the awake/start functions.
     
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    I would use OnEnable() to set up your UI, if it's an EditorWindow. For custom inspectors, use CreateInspectorGUI().

    As for just hiding stuff, use:
    - myVisualElement.style.display = DisplayStyle.None; // to hide completely and have it no even take up space
    - myVisualElement.style.visibility = Visibility.Hidden; // to have it still take up space but not render itself
     
  4. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    Ah OK thanks for the information. Now I can get back to building my editor window.