VContainer icon indicating copy to clipboard operation
VContainer copied to clipboard

VContainerSettings.Instance.RootLifetimeScope.Container is null

Open lancelodliu opened this issue 2 months ago • 2 comments

Description: Created a custom AppContext (inherits LifetimeScope) and assigned it as Root in a VContainerSettings asset. In a regular MonoBehaviour OnClick event I check: VContainerSettings.Instance.RootLifetimeScope.Container == null It is always true. I expected the root container to be built by then. This only happens in 1.17.0 version but not in 1.13.2.

Environment:

Unity: 6000.0.28f1c1 VContainer: 1.17.0 Platform: Windows Editor Mode Scripting Backend: Mono

Image

Steps To Reproduce:

Create AppContext: LifetimeScope, place it in the scene (enabled). Create a VContainerSettings asset, assign the AppContext as Root. Add a MonoBehaviour (TestBehaviour) to another GameObject. Enter Play Mode. Observe console logs: container remains null in when I click the GameObject.

lancelodliu avatar Oct 24 '25 14:10 lancelodliu

Also has strange behavior with RootLifetimeScope at 1.17.0, can`t find during runtime sometimes if select root as parent in LifetimeScope.

liderako avatar Oct 29 '25 10:10 liderako

It seems you should remove the existing AppContext instance from the scene and instead use one that is instantiated at runtime.

Before https://github.com/hadashiA/VContainer/pull/627, VContainerSettings.Instance.RootLifetimeScope was used directly as an instance. But now, it is just a prefab. (and runtime instance is instantiated) The commit is just after 1.13.2.

yellowisher avatar Oct 29 '25 10:10 yellowisher