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

Parent scope/container can not be resolved if I EnqueueParent simultaneously for two addictive scenes #507

Closed
vladyslavkhromykh opened this issue Apr 18, 2023 · 1 comment

Comments

@vladyslavkhromykh
Copy link

vladyslavkhromykh commented Apr 18, 2023

I think it might be some internal glitch speaking of timing in VContainer, maybe someone already had this issue.

Let's say, we have RootContext(assigned in VContainer settings) and BootContext(on the BootScene) that loads another 2 scenes.
Scene1 has Scene1Context on it, and Scene2 respectively has Scene2Context on it.
Btw, by Context, sure I mean inherited from LifetimeScope.

So, if I trying to start two coroutines in IStartable.Start() of Boot(entry point of BootContext), then Parent of Scene1Context becomes RootContext and not BootContext.
But, if I either load those two scenes in one using block(with EnqueueParent of course) or just by pressing some input keys in arbitrary points of time - all is OK, and both Scene1Context and Scene2Context have BootContext as it's parent.

Examples of code:

Coroutines with loading scenes

    private IEnumerator LoadScene1Async()
    {
        using (LifetimeScope.Enqueue(this.ServiceAInstaller))
        {
            using (LifetimeScope.EnqueueParent(this.Context))
            {
                var loading = SceneManager.LoadSceneAsync("Scene1", LoadSceneMode.Additive);
                while (loading.isDone == false)
                {
                    yield return null;
                }
            }
        }
    }
    
    private IEnumerator LoadScene2Async()
    {
        using (LifetimeScope.Enqueue(this.ServiceAInstaller))
        {
            using (LifetimeScope.EnqueueParent(this.Context))
            {
                var loading = SceneManager.LoadSceneAsync("Scene2", LoadSceneMode.Additive);
                while (loading.isDone == false)
                {
                    yield return null;
                }
            }
        }
    }

Starting coroutines in Boot.Start(in which case Scene1Context's parent becomes RootContext and not a BootContext)

    void IStartable.Start()
    {
        this.Context.StartCoroutine(this.LoadScene1Async());
        this.Context.StartCoroutine(this.LoadScene2Async());
    }

Loading scenes by input keys(works as predicted - every scene context has the same parent - BootContext)

    public void Tick()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            this.Context.StartCoroutine(this.LoadScene1Async());
        }
        
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            this.Context.StartCoroutine(this.LoadScene2Async());
        }
    }

Or third way(in which it does work pretty good as well)

    private IEnumerator LoadScenesAsync()
    {
        using (LifetimeScope.Enqueue(this.ServiceAInstaller))
        {
            using (LifetimeScope.EnqueueParent(this.Context))
            {
                var loading = SceneManager.LoadSceneAsync("Scene1", LoadSceneMode.Additive);
                while (loading.isDone == false)
                {
                    yield return null;
                }
                
                var loading2 = SceneManager.LoadSceneAsync("Scene2", LoadSceneMode.Additive);
                while (loading2.isDone == false)
                {
                    yield return null;
                }
            }
        }
    }
@hadashiA
Copy link
Owner

hadashiA commented May 7, 2023

Fixed in #513

@hadashiA hadashiA closed this as completed May 7, 2023
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