ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 363 forks source link

Prefab Instantiator not making use of existing InjectContext #585

Closed taylank closed 5 years ago

taylank commented 5 years ago

The following binding fails to find the parent transform: Container.Bind<EncounterCharacterUI>().FromComponentInNewPrefabResource("UIPrefabs/EncounterCharacterUI").UnderTransform(ctx => { var instance = (MonoBehaviour)ctx.ObjectInstance; return instance?.transform; }).AsTransient();

... because ObjectInstance comes back null. Upon inspection I realized the _prefabInstantiator inside GetAllInstancesWithInjectSplit method creates a new InjectContext, losing reference to the original context's ObjectInstance in the process.

Is this by design? If so, what is the reason for not creating a subcontext here?

svermeulen commented 5 years ago

No this is a bug. The context should be forwarded to the prefab instantiator.

svermeulen commented 5 years ago

Ok should be fixed now on master