If any future Zenject users like myself stumble upon this thread, I used a slightly different approach for injecting dependencies to graphs by foreach cycling through and injecting each node via my own extension method. This is very specific to my usage where I’m assigning graphs and creating GraphOwners at runtime, but you could use this same bit of code to create your own variation of the ZenAutoInjector monobehaviour included in Zenject to specifically inject to NodeCanvas graphs.
This allows you to use [Inject] attributes normally within your Node classes, rather than storing and retrieving injections in the Blackboard. For my own purposes, I’ve Injected the DiContainer and SignalBus to the base Node class so they are available to all derived types.
One word of warning: you’ll need to be aware of when NodeCanvas is deserializing through Initialize(). You need to inject after deserialization, hence why I manually call Initialize() manually in my Usage. There is probably a cleaner way to do this.
Attachments:
ExtensionMethod.png
Usage.png
Login
Register
By registering on this website you agree to our Privacy Policy.