Closed carmebar closed 7 months ago
Yeah, I agree 100% that being unable to use the Unity lifecycle of Awale/OnEnable/OnDisable is quite limiting.
Some libraries that achieve that injection before OnEnable, relies on the user adding a component to the scene which has the execution order set to a really low number, ensuring is the first one to happen. But this is not very reliable:
I already tought about this in past, but didnt found any reliable way of doing it.
One of my initial ideais was to run a AssetPostprocessor
that was going to add this "injection hook" component to all scenes, but this would only work for builds and not for editor time :/
Do you have any other ideas in mind @carmebar ?
I could think of a system that would work in editor by automatically injecting that component in all the scenes added to the build settings. But I feel that it might be too intrusive and could generate unexpected behavior for some users (like enumerating root objects and finding unexpected elements).
Does it make sense to create the "InjectEarly" component and treat it as optional in the documentation? As in: If you need earlier access to your dependencies remember to add this component in your scene. It would be great to improve the DX by finding a way to alert in editor when we detect that the developer is accessing the injected field before it has been assigned. I can't really think of a good way to do it without code generation, though...
@carmebar Honestly, there was quite of few people asking for this already, i'll be implementing and pushing this change between today and tomorrow.
@carmebar early injection is now supported beginning from v8, thanks for your feedback https://github.com/gustavopsantos/Reflex/releases/tag/8.0.0
Some of the injected dependencies have register/unregister mechanisms that fit very well with OnEnable/OnDisable lifecycle from Unity.
At the moment the way the library uses to get notified about scene loading makes the injected dependencies only ready for Start. Being unable to use the Unity lifecycle of Awale/OnEnable/OnDisable is quite limiting.
Is there a known workaround or a path forward that could be implemented? I am able to volunteer some developer time to implement the feature if is something that makes sense for the project.
Thanks in advance.