how to work with zenject?

NodeCanvas Forums Support how to work with zenject?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #11722
    loverains
    Participant

    how can i make custom task action using zenject injection?
    like

    #11724
    Gavalakis
    Keymaster

    Hello,

    Unfortunately I am not familiar with zenject at all.
    What are the requirements and what seems to be the issue in usage?

    Thanks and happy new year!

    Join us on Discord: https://discord.gg/97q2Rjh

    #11726
    loverains
    Participant

    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?

    #11741
    Gavalakis
    Keymaster

    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!

    Join us on Discord: https://discord.gg/97q2Rjh

    #14293
    rasooli.behnam
    Participant

    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.

    Attachments:
    You must be logged in to view attached files.
    #14996
    marshmatter
    Participant

    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:
    You must be logged in to view attached files.
    #15017
    Gavalakis
    Keymaster

    Thanks a lot for sharing with everyone 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.