Godot.DependencyInjection
Godot.DependencyInjection copied to clipboard
[Docs/Feedback] Injected members are unusable at `_on_ready`
DependencyInjectionManagerNode
injects all nodes at the Ready
stage.
This is called first to children, then to their parents. Because of this, all nodes have their fields set to null
even if the services are defined properly.
Not entirely sure what's the intended way of doing this, maybe you thought we should use this instead. Regardless, seems pretty easy to solve.
[Inject]
public void _ReadyInject() {}
I made my own solution which adds nodes in the tree implementing IServiceNode
to the service collection.
Edit:
The workaround shown above won't work for injected fields or properties. Fields and properties are not injected at the time the [Inject]
method is called, but parameters are.