NodeCanvas Forums › General Discussion › How are asset/unbound graphs supposed to be used?
Tagged: asset, blackboard, unbound
I’ve been making AI agents in Unity with bound behavior tree graphs. However now that I’m spawning player and enemy AI agents at runtime, I like the idea of being able to edit one graph used by all of them. But of course these AI agents need to be able to use references to other scripts/data on their agent. How is this approached with unbound graphs? If this isn’t possible with unbound graphs, how are they supposed to be used with BTs?
One easy option is to spawn the AI agent, and then bind the graph once its instantiated. How performance intensive is binding a graph at runtime like this?
What’s the “right” or standard way to handle one graph used by many agents like this, but needs to be able to use BBParameters or refrences some other way?
Thanks!
Hello there,
The main and most proper way to correctly utilize Asset Graphs, is by making their graph variables you need “Exposed Public”. You can make a variable “Exposed Public” through its “gear” icon menu. As soon as a graph variable is public hat way, it will have the following effects:
1) If the Asset Graph is directly assigned to a BTOwner, you will see all its public variables shown in the inspector of that BTOwner and possible to change; per-owner.
2) If the Asset Graph is used as a sub-graph within another parent graph, you will be able to “Map” the public graph variables of the sub-graph, FROM/TO the variables of the parent graph. This can be done through the inspector of the Sub-Graph node.
Please let me know if the above is of help. 🙂
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh
<span style=”color: #323232; font-family: ‘Open Sans’; font-size: 12px; background-color: #fbfbfb;”>1) If the Asset Graph is directly assigned to a BTOwner, you will see all its public variables shown in the inspector of that BTOwner and possible to change; per-owner.</span>
This way (#1) is what I’m looking to do. A few questions:
1) Does the variables being “public to change” include binding them, or just getting & setting values?
2) Are these BBParameters?
3) Is there an example of this set up anywhere that I could look at? Any more info/guides/tutorials etc with this setup?
4) Currently I have set things up so that the AI agent prefab assigns the BT to the BT Owner on Start() like so:
1 2 3 4 5 6 |
<span style="font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; color: #9586cf;">public </span><span style="font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; color: #a3dea1;">BehaviourTreeOwner </span><span style="color: #c6ccd3; font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; font-weight: bold;">btOwner</span><span style="color: #c6ccd3; font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; background-color: #222629;">;</span><br style="color: #c6ccd3; font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre;" /><span style="font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; color: #9586cf;">public </span><span style="font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; color: #a3dea1;">BehaviourTree </span><span style="color: #c6ccd3; font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; font-weight: bold;">behaviorTree</span><span style="color: #c6ccd3; font-family: 'JetBrains Mono', monospace; font-size: 13.0667px; white-space: pre; background-color: #222629;">;</span> <pre style="font-family: 'JetBrains Mono', monospace; color: #c6ccd3; font-size: 9.8pt;"><span style="color: #9586cf;">void </span><span style="font-weight: bold;">Start</span>() <span style="color: #4a9bf2; background-color: #383c40;">{ </span> btOwner<span style="font-size: 9.8pt;">.</span><span style="font-size: 9.8pt; color: #14b5a5;">StartBehaviour</span><span style="font-size: 9.8pt;">(</span><span style="font-size: 9.8pt; color: #20b1d2;">behaviorTree</span><span style="font-size: 9.8pt;">); </span>} |
But the way you describe in #1 doesn’t need this, right? Any code needed for that setup?
Thank you for the help!!
Bump.
Since it looks like the code I included is messed up two posts ago, here it is (I can’t edit that post for some reason). I can’t upload a code snippet properly so I’ve attached a screenshot of it.
Hello again,
1) “Public” graph blackboard variables can be bound to static properties/fields only.
2) If you mean the ones shown in the “variables mapping” inspector, then yes, those are special BBParameters (BBMappingParameter -> derived from BBParameter).
3) The setup is pretty easy 🙂 You just need to -Make an asset graph. -Make some of its variables “public”. -Use that graph as a subgraph in some other parent graph and Map the variables through the node inspector. I could send you an example if you need though.
4) If the BT is already assigned in the BTOwner through the inspector then this is not needed (but it doesn’t hurt as well).
Let me know if the above work for you.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
<span style=”color: #323232; font-family: ‘Open Sans’; font-size: 12px; background-color: #fbfbfb;”>If you mean the ones shown in the “variables mapping” inspector</span>
… wait WHAT?! What is the variables mapping inspector? Where is it? This sounds like exactly the solution to my problem! I couldn’t find anything on it in the documentation or the website.
I also could find absolutely nothing on exposed public graph parameters, namely how they’re supposed to be used. You should really consider adding some documentation on this stuff since its missing. 🙂
Thanks!
Hello again and sorry for the late reply!
The “Variable Mapping” inspector can be seen on any “SubGraph” node inspector. If you add any subgraph node (e.g. Subtree) in a graph, you will see the variables mapping on that node inspector through which you can map the subgraph public variables (there is related help text there as well).
You are right about the documentation. I do plan to update everything this month! 🙂
Join us on Discord: https://discord.gg/97q2Rjh