Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Some issues hiding UIDocument

Discussion in 'UI Toolkit' started by VentaGames, May 17, 2023.

  1. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    154
    Hi there, I'm new to UI Toolkit, so,
    I have two UIDocuments: Main Menu (order 0) and Scores (order 1).
    When i start the game, i hide scores with the following code:

    Code (CSharp):
    1. _scoresDocument.rootVisualElement.style.display = DisplayStyle.None;
    All works, fine. Then, when i click on the "Top scores" button and run:

    Code (CSharp):
    1. _scoresDocument.rootVisualElement.style.display = DisplayStyle.Flex;
    Still, all works fine.

    When i want to close this UIDocument, i run:

    Code (CSharp):
    1. _scoresDocument.rootVisualElement.style.display = DisplayStyle.None;
    And at this point, i see both screens at the same time.
    Why?

    Screen - 1: how they are organized
    Screen - 2: result.

    Screenshot 2023-05-17 at 11.42.34.png Screenshot 2023-05-17 at 11.38.32.png Screenshot 2023-05-17 at 11.42.34.png
     
  2. C-UITools

    C-UITools

    Unity Technologies

    Joined:
    Jun 23, 2021
    Posts:
    28
    Hello! Could you share details on your all 3 of your game objects? UI, Main Menu, and Scores?

    Thank you!
     
  3. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    154
    Hi again,

    Found the issue, it was my fault, I just set the "Clear Color" in the panel "clear settings" and the issue is gone.
    Check the attached image.

    P.s. for the best practice, it is ok, to organize multiple screens using my approach? I mean, empty GO and then a set of child UIDocuments? Or i can organize these pages inside of a single UIDocument?

    Thanks in advance.
     

    Attached Files:

  4. C-UITools

    C-UITools

    Unity Technologies

    Joined:
    Jun 23, 2021
    Posts:
    28
    So, the simplest way imo would be to have a master UXML with all of your other uxml included as templates inside of the master. Use that master in the UIDocument GO, then specifically set the display property to none so that the non-relevant templates are not rendered. That way, your code would always refer to the same asset.

    I'm not sure if that is the best practice in terms of performance (that would have to be checked out and I encourage you to try it on your end), but in terms of management, the option I mentioned would be simpler for me :)
     
  5. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    154
    Thanks for your reply.

    I've organized the main menu in the following way:

    Screenshot 2023-05-24 at 10.08.27.png

    As the menu background stays the same for all the child screens, i just
    enable/disable pages (they are transparent) using style.display = flex/none.