modesttree / Zenject

Dependency Injection Framework for Unity3D
MIT License
2.45k stars 270 forks source link

ZenjectSceneLoader - incorrect work #250

Open TarasLazorivInnovecs opened 2 years ago

TarasLazorivInnovecs commented 2 years ago

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):

brunocapdevila commented 2 years ago

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

TarasLazorivInnovecs commented 2 years ago

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