SubTrees: How to pass down agent and blackboard of the root BT?

NodeCanvas Forums Support SubTrees: How to pass down agent and blackboard of the root BT?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #14853
    aestatis
    Participant

    Hello, newbie here.  The documentation for the SubTree states “The agent and the blackboard of the root Behaviour Tree will be passed down to the SubTree, thus all available blackboard variables will be the same and available to the SubTree as well.”  However, when I add a SubTree to a BT, either manually or by right-clicking a composite node and selecting “Convert To SubTree”, the newly created BT is an Asset Reference and therefore is not bound to the agent and cannot contain any scene references.  Could someone please let me know if I am missing a step?  Any assistance is greatly appreciated!!  Example screenshot attached.

    Attachments:
    You must be logged in to view attached files.
    #14858
    Gavalakis
    Keymaster

    Hello there,

    As of v3, there are now two types of Blackboards available within a graph. One of them is the Graph Local Blackboard (which is part of the graph itself), and the second one the gameobject Blackboard (the one attached on the root Behaviour Tree Owner gameobject).

    The gameobject Blackboard is propagated down the subtrees in runtime but also in editor if you open a subtree through the parent tree (by double clicking the SubTree node for example). Please note that if you open the subtree asset directly this will not happen.

    Another way for passing variables down the subtree, is by mapping the SubTree’s variables to the parent tree’s variables, which can be done through the inspector of the SubTree node for all “exposed public” SubTree variables. Here are the steps of how this works.

    1. Create the variables you need in the SubTree and from their “gear” menu, set them as “Exposed Public”.
    2. In the SubTree node inspector found on the parent tree,  you will notice that you are now able to map the variables between parent and sub tree as “write in”, “read out”, or both. The most common one is “write in” which will basically set the subtree’s variable from a parent tree variable when the subtree starts.

    Please let me know if the above helps.

    Thanks!

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

    #14860
    aestatis
    Participant

    Thank you, that is the information I needed!

    #14986
    kylerberry
    Participant

    2. In the SubTree node inspector found on the parent tree,  you will notice that you are now able to map the variables between parent and sub tree as “write in”, “read out”, or both. The most common one is “write in” which will basically set the subtree’s variable from a parent tree variable when the subtree starts.

    Is there a proper example of doing this programmatically?

    #14991
    Gavalakis
    Keymaster

    Hello,
    Do you mean for mapping sub-graph variables through code only instead of using the GUI?
    If so, there isn’t an easy API for that, but the relevant code can be seen in IGraphAssignableExtensions.cs file.
    I could make a few methods for doing this through code only if that is indeed what you are after.
    Let me know.

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

    #14993
    kylerberry
    Participant

    Hi, yes that’s my intent. But perhaps you can point me to a better solution.

    I have a FSM with pluggable BT subgraph nodes. I’m trying to find a way to configure an FSM on a per agent basis with the relevant blackboard variables (since each BT has a different set of local variables that need to be passed down from the parent FSM).

    Perhaps I could assign all the variables the gameObject blackboard instead since they propagate to the sub graphs?

    see screenshot for what my FSM looks like

    I’m looking to have a single source of configuration for behaviors without needing to create a new FSM for every agent variation

    Thanks for your time

    Attachments:
    You must be logged in to view attached files.
    #15016
    Gavalakis
    Keymaster

    Hello again and sorry for the late reply.

    I see what you are after now. The problem with  subgraphs based on a variable, is that since the sub-graph is/can be dynamically assigned, we can’t do the variables mapping since mapping and variables are identified by a unique id instead of their name (so that it’s safe to rename variables without any problems). Of course all variables have their own ID and as such, even if two subgraphs share the same variable name, the mapping will be lost when changing from one subgraph to the other.

    One solution would be like you said, to set the mapping via code, but I think that this would become complicated to perform. I could however add some methods if that helps.

    Another solution would indeed be to use gameobject variables instead since you want to parametrize the sub-graphs per-agent and since variables mapping feature is not really possible (at least GUI-wise) because you are using different subgraph per agent (as far as I understand). I think that in this case (with dynamic sub-graphs), using the gameobject blackboard is probably better.

    If of course you have any other suggestions at all (some kind of feature or ability) that you think can help in what you want to achieve, please let me know.

    PS: Coincidentally, there is another post related to this where someone seems to have rolled some custom solution which may or may not work for you. I am still checking this out but maybe there is something that works for you there? -> https://nodecanvas.paradoxnotion.com/forums/topic/passing-variables-to-dynamic-subtrees/

    I also posted another possible solution in my answer in that post. For your convenience I am copy/pasting it for you here:

    “I could probably come up with and add a different mapping GUI approach (based on variable name matching) in SubTree inspector in place of the existing one, specifically when the subtree is dynamic. This way we could have the exiting variables mapping method for when the subtree is a constant assignment and a different mapping method for when subtree is dynamic.”

    Thanks!

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

    #15020
    kylerberry
    Participant

    Hi, thanks so much for the thorough response.

    I’m glad to see that I wasn’t going crazy, every time I tried to piece-together a solution, it sort of felt like it was flying in the face of the NC patterns already in-place. This explains why I couldn’t get those variables to map manually, I didn’t realize they had different refs.

    I will take a look at the post to see their solution. Though, I’d like to do as minimal home-rolling a solution as possible since I’m still new to C# (programming for years, new to gamedev though)

    I like your proposed solution of a different mapping approach in a “dynamic” subtree. I think this would address my use-case of trying to create new enemy types with different behavior parameters programmatically. For starter’s I’ll see if I can workaround a pattern that focuses on the gameObject blackboard.

    I’ll post my solution here if/when I find it. Thanks for your insight!

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