I understand how to run a subgraph and how I add a behavior graph to a Behavior Agent. But I don’t understand what I do with the subgraph. Do I have to add the subgraph to a Behavior Agent as well?
In case of adding the subgraph to a Behavior Agent, the subgraph blackboard variables will be instantiated , but the behavior of the subgraph will also start immediately and doesn’t wait for the “run subgraph” action.
When I don’t add the subgraph to a Behavior Agent the subgraph will start after “run subgraph” action, but the subgraph blackboard variables are not instantiated.
What is the way forward? Any examples of using subgraphs?
Hi @Mark_1975 ,
The best example at the moment is in the demo @MorganHoarauUnity made: Behavior Demo For Unity | Tutorials | Unity Asset Store
But to try and answer your questions: you don’t need to add the subgraph to the agent.
There are 2 types of subgraphs: Static and dynamic.
Static Subgraphs are when you link the Subgraph to the Run Subgraph node using the asset tab after clicking the search button. These are unchangeable at runtime and you know exactly what you’re getting.
Dynamic Subgraphs are when you link a Subgraph Blackboard Variable to the same node. With these you have to ensure the blackboard variable contains a valid graph. Note that when selecting a variable here, you can also assign a Blackboard Asset variable to the node to use as an interface across the main graph and the subgraph. At runtime we will check that the subgraph indeed contains said interface.
All that said, please note we found a pretty big issue with Dynamic Subgraphs in 1.0.7. and are hoping to release a fix in the next few days.
Additional documentation on this can be found here:
https://docs.unity3d.com/Packages/com.unity.behavior@1.0/manual/node-types.html#subgraphs-node-types
Thanks, I was testing static subgraphs and on the subgraph’s blackboard there are some variables. The values of these variables should be assigned, but without adding the subgraph to an agent you cannot use the unity inspector to assign a value.
Does it mean that the main graph must always override the subgraphs values?
Or is there a better way to do this, because in my case the main graph has no knowledge about the subgraphs values and shouldn’t have.
I looked at the demo, but this demo is a bit to complicated for me without further explanation. I also noticed that it is hard to find all the agents in the scene.
I’m not sure I’m understanding you correctly here. Maybe you can help clarify? Are you adding the subgraph to the agent, or in the graph?
In practice, you should only have the main graph assigned to the agent. The static subgraph assigned in that graph. Then the node will show the blackboard variables it has, allowing you to link them to your current blackboard however you see fit.
I believe non Object value will show the default ones where possible, but Object values will need to be assigned. We can’t show you any variables if there is no static subgraph assigned 
Also we don’t show Subgraph variables in the Agent inspector, you have to assign a variable through the graph for the time being. This is something we can improve on UX-wise.
I didn’t add the subgraph to the agent, I only added the subgraph in the graph. But after giving it some thought I was trying to do something what doesn’t match.
I wanted to create a subgraph to isolate specific behavior including specific variable assignments, and while doing this I wanted to keep the parent graph as simple as possible and I definitely didn’t want to add variable assignments for the subgraph in this parent graph.
And after some thinking I concluded that I am not looking for a subgraph, but a separate independent behavior that can be react on assignments coming from other graphs. Am I right that I have to use event channels for this?
I would create a behavior graph and add it to a behavior agent and add a wait for assignment statement at the top of the graph.
Yes! Event channels are a good way to do this for sure. You can potentially also use a Dynamic subgraph here. Please note 1.0.8 is out with a bunch of fixes related to Dynamic Subgraphs 
Thanks. I already started using 1.0.8, and will also look into Dynamic Subgraphs.
I want to elaborate a little bit about the use case. It is an assignment to spin a wheel. So I need 2 graphs:
- a graph to receive the assignment, make the wheel spin and send an event when the wheel stopped spinning
- a graph to send the assignment to spin the wheel and receive an event when the wheel stopped spinning
Not so difficult. But there is only 1 wheel and multiple agents that want to spin the wheel:
- a queue is necessary to prioritize the assignments (FIFO)
- an agent must join the queue to send an assignment
- the agent has to wait for his turn and can send an assignment when it is his turn
- after sending the assignment the agent waits for the result
- if the result is satisfactory, the agent releases his spot in the queue for the next agent
Would such a queuing system be doable with behavior graphs?