Request: Support for interfaces in generic actions

NodeCanvas Forums General Discussion Request: Support for interfaces in generic actions

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12611
    jhorrocks
    Participant

    Types for generic actions are currently constrained to be UnityEngine.Objects. It would be very useful to target Components on the GameObject which implement an interface instead. Would this be possible to implement since GetComponent<> has supported interfaces for quite some time? Thanks

    #12621
    Gavalakis
    Keymaster

    Hello,

    Targeting interfaces is already possible, but as of now, it is done with a workaround and by using the special [AgentType] attribute. With that said, to support interfaces in the generic actions, all you have to do is please open up ActionTask.cs and change line #14..
    From This:

    To This:

    With this change, then you will be able to do something like this:

    It will also work in the inspector as usual 🙂
    AgentTypeExample

    (You can also do the same change in ConditionTask.cs if you want so).

    This small change will also make it in the next version.
    Let me know if that works for you.

    Thanks.

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

    Attachments:
    You must be logged in to view attached files.
    #12686
    jhorrocks
    Participant

    Hi, thanks very much for the reply. Apologies for the delay I was on vacation. My coworker tested this and wanted to relay two problems he found:

    1. Implementations of an interface which do not subclass components break the GUI in the inspector and blackboard view in the Canvas screen. Attempts to interpret them as Components when they should be rendered with the object view instead
    2. Agents not subclassing components, when assigned with a dynamic variable, have their references lost at start. Says that the agent is null or not set. The dynamic identifier is definitely set correctly at editor time, and the object is populated in the blackboard at runtime.

    Hope that helps.

    #12689
    Gavalakis
    Keymaster

    Hello,

    I hope you had a great time on your vacation 🙂
    The whole system is built around agents being a Component subclass type, so even though with this change you can use an interface for “Agent Type”, the concrete type must still derive from Component. Is your use case to use non-component derived agents from say Blackboard Variables?

    Thanks.

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

    #12695
    jhorrocks
    Participant

    Thanks! Yes, it is.

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