Skip to content

Throwing a null reference exception during an "Install" method call with a UI Document on scene #67

Open
@naxa1ka

Description

@naxa1ka

Describe the bug
Right at the start of the scene, an exception is thrown while calling the install method in the scene context:

ArgumentNullException: Value cannot be null.
Parameter name: e
at UnityEngine.UIElements.UQueryExtensions.Query (UnityEngine.UIElements.VisualElement e) 

Line 305 in the SceneContext script.

To Reproduce
Add a UI Document to the scene
Add some Installer and scene context
Run the scene in WebGL

Repository example
Repository with a ready-made example:
https://github.com/naxa1ka/Zenject_Toolkit_Issue_Example
The readme in repository contains all the details of the environment

Expected behavior
Exception will not be thrown
If the idea of the lines that caused the bug was to inject dependencies into the ui document

Screenshots
image

Extenject and Unity info (please complete the following information):

  • Zenject version: 9.3.1
  • Unity version: 2021.3.11f1
  • Project's scripting backend: WebGL

Additional context
Exception thrown at rootVisualElement.Query()
My guess is that the problem is that the UI Document has [DefaultExecutionOrder(-100)], due to which the rootVisualElement is not yet ready to run during the Install method

Error code

SceneContext.cs
297 #if USE_UI_ELEMENTS_PACKAGE || (USE_UI_ELEMENTS_MODULE && UNITY_2021_1_OR_NEWER)
298           List<GameObject> rootObjectsInScene = new List<GameObject>();
299        gameObject.scene.GetRootGameObjects(rootObjectsInScene);
300           for (int i = 0; i < rootObjectsInScene.Count; i++)
301            {
302                UIDocument[] uiDocuments = rootObjectsInScene[i].GetComponentsInChildren<UIDocument>(true);
303               for (int j = 0; j < uiDocuments.Length; j++)
304               {
305                   uiDocuments[j].rootVisualElement.Query().ForEach(x => _container.QueueForInject(x));
306               }
307           }
308 #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions