Skip to content

GetRuntimeParent called in Awake is inconvenient. #725

@majesty77

Description

@majesty77

VContainer: v1.16.4

Even if autorun is set to false in Awake, GetRuntimeParent is called and the Parent is set.
This is not convenient in the following situations

// With VContainerSettings.Instance.RootLifetimeScope set.
// Assuming the autorun of the LifetimeScope Prefab for this key's address is set to false
var handle = await Addressables.LoadAssetAsync<LifetimeScope>(key);
var result = handle.Result;

// Internal Awake sets Parent to VContainerSettings.Instance.RootLifetimeScope
var instance = Instantiate(assetLoadHandle.Result); 

// I call Build with parentScope as parent at another time, but it doesn't work as intended because Parent is already set
using (LifetimeScope.EnqueueParent(parentScope)) {
    instance.Build();
}

I think it would be better if the Parent is determined at Build time, since the Parent resolution process is also performed inside Build, so I think it would be better to remove the GetRuntimeParent that is called in Awake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions