Zenject icon indicating copy to clipboard operation
Zenject copied to clipboard

ZenjectSceneLoader - incorrect work

Open taras-lazoriv-innovecs opened this issue 4 years ago • 2 comments

When you load additive scene by default SceneManager (that contains SceneContext), and after that trying to load new additive scene by ZenjectSceneLoader with some binding to context - Bindings will be applied to the first scene.

To Reproduce

SceneManager.LoadSceneAsync("FirstScene", LoadSceneMode.Additive);
m_zenjectSceneLoader.LoadSceneAsync("SecondScene", LoadSceneMode.Additive, container =>
        {
            container
                .Bind<Camera>()
                .FromInstance(Camera.main)
                .AsSingle();

        });

FirstScene and SecondScene both have SceneContext

Expected behavior SecondScene must have binded class Camera

Current behavior FirstScene have binded class Camera

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

  • Zenject version: 9.2.0
  • Unity version: 2021.1.16f1
  • Project's scripting backend [e.g. Mono/IL2CPP] : any

taras-lazoriv-innovecs avatar Sep 21 '21 08:09 taras-lazoriv-innovecs

Hi! If you look into the method ZenjectSceneLoader is using some static variables inside SceneContext. It is kind of ugly, but right now it is the way it is...

If you want to work around it, just await/yield the first scene load then start the next one

brunocapdevila avatar Oct 27 '21 16:10 brunocapdevila

Hi! If you look into the method ZenjectSceneLoader is using some static variables inside SceneContext. It is kind of ugly, but right now it is the way it is...

If you want to work around it, just await/yield the first scene load then start the next one

Hi, yes that workaround I use for now. I hope zenject will allow to bind dependency into two parallel scenes

taras-lazoriv-innovecs avatar Oct 29 '21 10:10 taras-lazoriv-innovecs