for zenject,the dependency can be inject through container.
but in node canvas,action task instance is deserialized from assets.
i can’t get dependency by inject way,and i can’t depend on interface,only can depend on concrete monobehaviour.
have you any thought?
Hello again and sorry for the late reply.
Sorry, but I didn’t check out zenject due to christmas vacation, but I will do so in the next couple of days and get back to you if I have any insights on this. I can’t say for sure whether this will be possible though.
Thanks in advance!
There is no way you can inject it, but you can add the DiContainer to the graph’s blackboard inside your Zenject installer and then retrieve it inside your NodeCanvas custom code. From there you can resolve your types directly from the DiContainer. For instance, I’m getting a reference to the DiContainer inside my custom state.
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.