Search Unity

Bug rootVisualElement is null during runtime

Discussion in 'UI Toolkit' started by ThePeat, Sep 6, 2021.

  1. ThePeat

    ThePeat

    Joined:
    Dec 25, 2014
    Posts:
    1
    Unity version: 2021.1.17f1
    UI Toolkit version: 1.0.0-preview.16

    In the editor during playmode my UI Toolkit UIs work fine. When I create a PC build the rootVisualElement from any UIDocument suddenly is null.

    Code (CSharp):
    1.         [Inject]
    2.         public void Construct(UIDocument uiDocument, IBuildValidator buildValidator)
    3.         {
    4.             this.m_uiDocument = uiDocument;
    5.             this.m_uiDocument.rootVisualElement.style.display = DisplayStyle.None; // rootVisualElement is null during build runtime, throws a null reference exception. Is fine during editor runtime
    6.             this.m_buildValidator = buildValidator;
    7.         }
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    192
    It is possible that Construct is called too early. Did you try to delay this call? What is the call stack? Also are you building for mono or il2cpp?
     
  3. Slandercakes

    Slandercakes

    Joined:
    Jul 30, 2015
    Posts:
    15
    I'm experiencing the same behaviour. Works fine in the editor, but in a Windows build the rootVisualElement field is always null. Is there a workaround for this?

    Edit: I should add that I've tried delaying the call.
     
  4. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    192
    The best way to tackle this issue would be that you submit a repro through the bug reporter so we can investigate. You can so do in Help>Report a bug...
     
unityunity