How should I manage shared data and behaviours using subgraphs

I am trying to come with a system using behavior graph for a unique NPCs.
The NPCs have some common behavior (dynamic) driven by the environment - talking to each other ect.
They have unique behavior that is set in their own behavior graph.

I have tried to create a subgraph that can be reused for all NPCs but I am struggling with a few things.

  1. I am using the “CharacterMovement” blackboard to store values used for navigation if I share the values they can be used by the subgraph but then all the instances of “DynamicBehavior” are using the same values, so I can’t change them per NPC. If I don’t share them then I have to duplicate them on the subgraph and link them.

  2. I am using “CharacterMovement” to help organize the blackboard variables if I add it to the subgraph “DynamicBehavior” there is no way to assign values to it from the “Run Subgraph” node.

What is the best approach to share common behavior between NPCs and is there a better way to link values from the parent graph to the subgraph without duplicating them?

I am currently seeing a bug where changes to the subgraph are now no longer having any immediate effect, it will just run a cached version. Currently I am deleting runtime assets and then reattaching the graphs to the BehaviorAgent components in order to get changes to be run. I think this had been bugged already, but let me know if I can provide more information.

Hi @StaphiX

Really sorry for the very big delay, a lot happened in February and your question flew under the radar.

This was due to a bug that has been resolved in 1.0.8:

  • Run Subgraph (Dynamic) wasn’t initializing a copy of the graph asset correctly, causing data to be shared amongst agents sharing the graph and corrupting the graph asset.
    Changelog

It exist 2 versions of Run Subgraph (documentation):

  • Static/Default - when assigning a graph asset directly
  • Dynamic - when assigning a blackboard variable of type Subgraph to it

As you are using “CharacterMovement” blackboard asset, you should use RunSubgraph Dynamically and you will be able to provide the “CharacterMovement” asset to the node that will act as an interface.

To do so, create a BlackboardVariable<Subgraph> and set it’s value to your DynamicBehavior graph. Then assign this BBV to the RunSubgraph node:

Yes, that was a bug with Static Subgraph that was also fix in 1.0.8:

Static subgraphs now have their parent rebuilt when saved.

Hope this will helps clarify the situation. We had a lot of unspotted issues with Subgraphs before 1.0.8 and you seemed to have hit a lot of them.

Again, we are really sorry for the long delay :person_bowing: