ssannandeji / Zenject-2019

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

Awake running before Construct with DecoratorSceneContext #624

Open nexxogen opened 5 years ago

nexxogen commented 5 years ago

The package in the attachment contains everything to reproduce the bug. Open and run the 'Decorator Scene'.

To quickly describe the problem, there are two scenes, Main and Decorator. Main has a SceneContext while the Decorator has a DecoratorSceneContext. Both of these scenes have MonoBehaviour classes in them (MainSceneMono and DecoratorSceneMono) which expect dependencies from the other scene. The DecoratorSceneMono also has an Awake method which runs the 'SayHello()' method of the Foo class, which is bound in the Main Scene. Upon running the scene, the Awake method of the DecoratorSceneMono executes before the [Inject] Construct() method. Tests with Start() and OnEnable() have shown this execution order:

Awake() -> OnEnable() -> [Inject] Construct() -> Start()

[Unity Package] (https://github.com/modesttree/Zenject/files/3034209/DecoratorContext.zip)