Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
naxa1ka opened this issue Dec 13, 2022 · 1 comment

Comments

@naxa1ka
Copy link

naxa1ka commented Dec 13, 2022

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
@denravonska
Copy link

Duplicate of #55 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants