Skip to content
Discussion options

You must be logged in to vote

Here’s a clean way to share a DataPlayerManager across scenes with VContainer.

  1. Create a root scope that survives scene loads

Make a GameLifetimeScope (subclass of LifetimeScope) in your bootstrap scene and register the manager as a singleton. Check DontDestroyOnLoad on the LifetimeScope component.

using VContainer;
using VContainer.Unity;
using UnityEngine;

public sealed class GameLifetimeScope : LifetimeScope
{
    protected override void Configure(IContainerBuilder builder)
    {
        // One instance for the whole app
        builder.Register<DataPlayerManager>(Lifetime.Singleton);
        // Or: builder.RegisterInstance(new DataPlayerManager(...)).AsSelf();
    }

    protected o…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SevenDOnWay
Comment options

Answer selected by SevenDOnWay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants