Skip to content

Commit

Permalink
Merge pull request #121 from cooloon/cooloon/stop-prefab-inactivation
Browse files Browse the repository at this point in the history
Restore prefab state after instantiation
  • Loading branch information
hadashiA authored Feb 12, 2021
2 parents 7e7f229 + 8927468 commit c72a6be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ public LifetimeScope CreateChild(Action<IContainerBuilder> 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);
Expand Down

0 comments on commit c72a6be

Please sign in to comment.