Fully synchronized variables for nested graphs (e.g. SubTree)

NodeCanvas Forums Support Fully synchronized variables for nested graphs (e.g. SubTree)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16237
    joshh
    Participant

    Hi, I want to have parameters on a nested node such as SubTree in BTs that are continuous read and continuous write. Right now, the variable is only set once when the sub graph starts, but after the sub graph has started any change of the parameter from the parent graph will not be reflected in the sub graph.

    It seems there is no built-in way to do this, so my idea is to create custom nested graph nodes. As an example, I will talk about the SubTree BT Node.

    As far as I understand the binding of variables happens in the TryWriteAndBindMappedVariables and the cleanup happens in TryReadAndUnbindMappedVariables both of which are located in the IGraphAssignableExtensions.cs

    Would it be enough to change the one time write:

    if ( bbParam.canWrite ) { targetSubVariable.value = bbParam.value; }

    to:

    if ( bbParam.canWrite ) {
        targetSubVariable.value = bbParam.value;
        if(bbParam.varRef != null) {
            bbParam.varRef.onValueChanged += targetSubVariable.SetValueBoxed;
        }
    }
    Also adding the matching clean-up in the TryReadAndUnbindMappedVariables method.
    1. This solution seems to work in my first test but I would love to know if I am missing something?
    2. Could this lead to endless event calls (bbParam onValueChanged sets target variable which triggers its onValueChanged and sets the bbParam triggering the onValueChanged -> and so on…)
    3. What were the considerations for implementing a one time write in instead of fully synched variables? Are there good reasons not to do this?

    Any help is appreciated!

    #16242
    Gavalakis
    Keymaster

    Hello Josh,

    Your code change should work fine 🙂

    1) You are not missing anything. All the functionality related to variables mapping is basically within those two methods.
    2) It should not lead to endless loop since setting a variable first checks if the new value is != to the existing value.
    3) The consideration was for subgraph exposed variables to work similar to how code function parameters work, meaning that they are only given once when the function is called. It just made more sense to me to write-in only when the subgraphs starts, but I suppose that an option needs to be added to let us select in inspector a “once” or a “synchronous” write-in (and probably read-out as well).

    Thanks!

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

    #16243
    joshh
    Participant

    Thanks for the explanation. For now, I will probably implement variants of the subgraph nodes  with my desired write-in behaviour to not mess with the built-in functionality. If you include an option to set the write-in to continuous in the official node canvas package, it would be highly appreciated.
    Keep up the good work 🙂

    #16251
    Gavalakis
    Keymaster

    Hey.

    I’ve noted this down and will look at adding this as an option in the future 🙂

    Thanks!

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

    #16772
    slava
    Participant

    Hi there. I think, I’d need the same feature. But as I understand, this feature hasn’t been added officially yet, right?

    #16802
    Gavalakis
    Keymaster

    Hello there,

    Sorry no, continously writing in the mapped variables while the subgraph is running hasn’t been implemented yet (basically only because it is not something requested that much). Is indeed continously writing in the mapped variables while the subgraph is running what you requeste? If so, I will move that up in priority in the TODO list. 🙂

    Thanks.

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

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