Hello! I’d like to make AI modular so weapons can bring their own behavior graphs.The main graph holds the common AI logic for all agent archetypes.
A blackboard variable (Subtree Slot) points to the currently equipped weapon’s subtree.
If it’s null, it falls back to a default unarmed attacks subtree, which should also be settable from the blackboard.
When an NPC equips a weapon, that weapon assigns its subtree to the slot; when dropped, the slot clears.
Basically, I want to load a subtree with the weapon logic in another subtree that keeps the shared combat logic.
The combat logic is keept in the main subtree that keeps the subtrees for all the behaviours (combat, wander, idle etc)
I experimented a bit with ISubtreeReference , but from what I understand it’s designed for a list of subtrees that get loaded once with the main graph.
What I’m looking for is something more dynamic.
```
public class SubTreeLoader : ActionNode, ISubtreeReference
{
public SharedVariable<Subtree> subtreeReference;
[Tooltip("The variables that should override the subtree variables.")]
[SharedVariableOverridesListAttribute]
[SerializeField] protected SharedVariableOverride[] m_Variables;
private Subtree[] selectedSubtrees;
public SharedVariableOverride[] SharedVariableOverrides { get => m_Variables; set => m_Variables = value; }
public Subtree[] Subtrees => selectedSubtrees == null ? new Subtree[1] { subtreeReference.Value } : selectedSubtrees;
public void EvaluateSubtrees(IGraphComponent graphComponent)
{
if (selectedSubtrees == null)
selectedSubtrees = new Subtree[1];
selectedSubtrees[0] = subtreeReference.Value;
}
}
```
A blackboard variable (Subtree Slot) points to the currently equipped weapon’s subtree.
If it’s null, it falls back to a default unarmed attacks subtree, which should also be settable from the blackboard.
When an NPC equips a weapon, that weapon assigns its subtree to the slot; when dropped, the slot clears.
Basically, I want to load a subtree with the weapon logic in another subtree that keeps the shared combat logic.
The combat logic is keept in the main subtree that keeps the subtrees for all the behaviours (combat, wander, idle etc)
I experimented a bit with ISubtreeReference , but from what I understand it’s designed for a list of subtrees that get loaded once with the main graph.
What I’m looking for is something more dynamic.
```
public class SubTreeLoader : ActionNode, ISubtreeReference
{
public SharedVariable<Subtree> subtreeReference;
[Tooltip("The variables that should override the subtree variables.")]
[SharedVariableOverridesListAttribute]
[SerializeField] protected SharedVariableOverride[] m_Variables;
private Subtree[] selectedSubtrees;
public SharedVariableOverride[] SharedVariableOverrides { get => m_Variables; set => m_Variables = value; }
public Subtree[] Subtrees => selectedSubtrees == null ? new Subtree[1] { subtreeReference.Value } : selectedSubtrees;
public void EvaluateSubtrees(IGraphComponent graphComponent)
{
if (selectedSubtrees == null)
selectedSubtrees = new Subtree[1];
selectedSubtrees[0] = subtreeReference.Value;
}
}
```



