Missing Functionality - Sharing blackboard variables across a single agent's trees

I’m working in Unity 6.2 with Behavior version 1.0.13, and finding it more complicated than it should be to share variables across an agents subtrees. BB Variables have two modes:

  • Non-Shared: Local to one graph instance on one agent.
  • Shared: Global to all agents and graphs.

But shouldn’t there be an ‘Agent’ mode where the variable is shared across all instances of a BB on a single Agent?

Perhaps the subtree variable override system is supposed to accomplish that, but it seems very impractical to manually override each BB variable at each graph layer, especially for intermediate layers that might not use particular variable.

It would save a lot of time and opportunity for human error is I could simply pass in an entire BB and automatically override all of its fields on the subgraph, but ideally I could just have BB variables that could be set to be shared across all graphs on a single agent.

You can attach a custom “AgentData” component to the GameObject. Give it a try.

That is the workaround I’m planning to use, but it is definitely not as convenient as being able to share a BB value across an agent’s subgraphs.

I would probably still want to pass a reference to it down through the tree structure rather than potentially invoke Self.GetComponent() a bunch of times per frame. Overriding one reference field is better than having to do one for each field in a blackboard, but not as convenient as simply making a bb variable agent-global.

Hi @quinng, thanks for the feedback!

This does sounds like a pain point with the current variable scoping system, and your request for agent-scoped variables makes sense.

Based on your feedback, we’ve identified a couple of bugs/limitations that are likely contributing to your workflow challenges:

  1. Dynamic subgraph auto-linking isn’t working properly: When using Run Subgraph Dynamically (using a blackboard variable of type Subgraph instead of a direct asset reference) with a blackboard asset that’s also linked to the parent graph, the variables should automatically connect, but this isn’t happening reliably. Another users reported something similar in the past here. We’ll need to fix this. (Ticket: https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-131083 )
  2. Static subgraphs can’t access linked blackboard assets: Currently, static subgraphs (using Run Subgraph nodes) only expose their embedded blackboard variables and can’t access variables from linked blackboard assets. This might limits the modularity you’re looking for. I believe this is a case due to some limitation in the early design of the package, but that might be something we could look into improving in the future.

I like the idea of providing a “Scope” enum option (Local, Agent, Global) instead of just a “Shared” boolean. However this requires careful design consideration to maintain the modular nature of behavior graphs while providing intuitive UX. This is not something that we will be able to prioritize for a while. But your feedback is a valuable input to start building a user story.

Edit: Added ticket for blackboard asset’s variables auto-link bug.

I do agree that a scope enum with Local, Agent, and Global settings would solve my use case, and I do think that is the best long-term solution. For usability and clarity it might have been better to set this for an entire blackboard instead of each variable, but that ship has probably sailed.

But since that is a long-term change, I do agree that getting subgraphs working consistently is an important priority. The lack of shared Blackboard settings on static subgraphs initially made me assume that they would automatically share the parent graph’s blackboard values, but unfortunately that is not the case.

FYI, a user reported a similar request.

In their case I suggested the use of EventChannel to workaround the current limitation. Sharing in case it might be of interest: Can you access a subgraph's variable's value from the main graph? - #2 by MorganHoarauUnity

My workaround is an external component that holds a dictionary. It means I have to write separate actions to get, set, and otherwise operate on each variable type, but until we have agent scope variables I think that is the only workaround.

Having worked with the system more, it seems that changes in injected bb variables do not propagate to the parent blackboard. This was unintuitive to me, since it seems to run counter to what a blackboard is supposed to do. The last graph tree system I worked with had both concepts, a one-way parameters interface for passing information down to subgraphs, and a separate agent-wide blackboard where subgraphs could manipulate shared variables.

I did implement an EventChannel, and I do see how they are a good interface for downstream level designers to control the behavior of specific instances of an AI entity. However, I wanted all instances of an entity to have their own event channel for when a player clicked on them. To do this, I instantiate an event channel instance in code and pass it in to the agent’s root behavior graph blackboard. However, I then need to manually pass the event channel down every subgraph chain where I might want to listen to it, which runs into all the same issues with static and dynamic subgraph interfaces being inconsistent. Eventually I’m going to have a number of standard events, which will amount to a lot of busy work manually making sure that each event channel object is passed down to subgraphs.

Agent scope variables would making it a lot more convenient to pass in event channel instances, but ideally I’d just like to be able to ping an agent with something like:

agent.SendMessage<BehaviorGraphMessageType>(messageObject)

And have message listeners in all the agent’s active behavior trees catch the message. So I would define a BehaviorGraphMessageType as a class (or maybe just regular Events or Actions would work) and I wouldn’t need to create instances of event channels in code for each entity instance.