Search Unity

Resolved UI Toolkit displaying in editor but not on mobile?

Discussion in 'UI Toolkit' started by billy-PnT, Sep 10, 2021.

  1. billy-PnT

    billy-PnT

    Joined:
    Sep 7, 2021
    Posts:
    2
    I've just been trying to get a feel for the UI Toolkit and I feel like I'm not setting something up correctly.

    I've included all the proper packages according to this forum post and my scene currently looks like this:

    SampleScene
    - Main Camera
    - Directional Light
    - UIDocument

    Following the documentation here, I've set up my UIDocument (game object) with:

    - Input System Event System (UI Toolkit)
    - UI Document:
    * Panel Settings: PanelSettings (asset)
    * Source Asset: SimpleUI (my uxml asset)

    If I push play in the editor, my UI shows up, but when I build and run the project for iOS or Android, I only see the 3d scene. Anyone have any ideas of what I could be missing?

    Here's a link to the project if that helps.

    Thanks.

    Relavent Versions:

    Unity – 2020.3.18f1
    UI Builder – 1.0.0-preview.17
    UI Toolkit – 1.0.0-preview.17
    Unity UI – 1.0.0
     
  2. MizterRaven

    MizterRaven

    Joined:
    Apr 28, 2015
    Posts:
    8
    Not sure how to directly fix what's happening to you, but I was having trouble with UI Toolkit stuff a few weeks ago and switched to editor version 2021.2 which has all the appropriate packages installed by default. That solved all the problems I was having.
     
  3. billy-PnT

    billy-PnT

    Joined:
    Sep 7, 2021
    Posts:
    2
    I tried a similarly made sample in 2021.2 and that worked for me too.

    Going back to my original code, it seems like in the difference between 2021.2 and 2020.3 when using UI Toolkit in mobile is that they don't seem to show automatically in 2020.3 like it does in 2021.2.

    Just in-case anyone else has this issue, I resolved it by creating another GameObject in my scene with a Script component that references a UIDocument (in my example, the one that references SimpleUI) and in Start(), I updated it's display style so that it would show:
    Code (CSharp):
    1. public UIDocument uiDocument;
    2.  
    3. // Start is called before the first frame update
    4. void Start()
    5. {
    6.     if (uiDocument != null) {
    7.         uiDocument.rootVisualElement.style.display = DisplayStyle.Flex;
    8.     }
    9. }
     
  4. epsilon840

    epsilon840

    Joined:
    Aug 30, 2022
    Posts:
    3
    Also can be usefull - some VisualElement can become visible = false for Android, although they are visible = true in editor.