diff --git a/VContainer/Assets/VContainer/Runtime/Unity/ComponentRegistration.cs b/VContainer/Assets/VContainer/Runtime/Unity/ComponentRegistration.cs index d9ccd576..deb8454e 100644 --- a/VContainer/Assets/VContainer/Runtime/Unity/ComponentRegistration.cs +++ b/VContainer/Assets/VContainer/Runtime/Unity/ComponentRegistration.cs @@ -114,6 +114,7 @@ Component FindComponent(IObjectResolver resolver) Component InstantiatePrefab(IObjectResolver resolver) { var parent = destination.GetParent(); + var wasActive = destination.Prefab.gameObject.activeSelf; if (destination.Prefab.gameObject.activeSelf) { destination.Prefab.gameObject.SetActive(false); @@ -123,6 +124,7 @@ Component InstantiatePrefab(IObjectResolver resolver) ? UnityEngine.Object.Instantiate(destination.Prefab, parent) : UnityEngine.Object.Instantiate(destination.Prefab); + destination.Prefab.gameObject.SetActive(wasActive); injector.Inject(component, resolver, Parameters); component.gameObject.SetActive(true); return component; diff --git a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs index 3647e11d..71c184ee 100644 --- a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs +++ b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs @@ -203,12 +203,14 @@ public LifetimeScope CreateChild(Action installation) public LifetimeScope CreateChildFromPrefab(LifetimeScope prefab, IInstaller installer = null) { + var wasActive = prefab.gameObject.activeSelf; if (prefab.gameObject.activeSelf && prefab.autoRun) { prefab.gameObject.SetActive(false); } var child = Instantiate(prefab, transform, false); + prefab.gameObject.SetActive(wasActive); if (installer != null) { child.extraInstallers.Add(installer);