Hi! I'm new in the forum, but I've been using playmaker since 2019!
I'm currently working with PM to make better AI, using it with Behavior Designer (From opsive).
My current setup is very simple and looks something like this:

When FSM enters in some state, it activates a Behavior Tree. The Behavior Trees, executes the actions of the AI and in some specific cases, sends an event to the FSM to change it status and allow another behavior tree to execute.
That works fine, but the current integration between the two tools requires setup first all the Behavior Trees in the inspector and then assign them a different group in order to be able to work with them in Playmaker.
So, to fix this and improve the workflow, I've created a simple task that before enabling the behavior Tree, actually adds it to the gameobject. My task looks something like this:
public class BehaviorTreeExtended : FsmStateAction
{
public ExternalBehaviorTree ExternalBehaviorTree;
public BehaviorSource BehaviorSource;
public override void OnEnter()
{
base.OnEnter();
var behaviorTree = Owner.AddComponent<BehaviorTree>();
behaviorTree.ExternalBehavior = ExternalBehaviorTree;
foreach (var variable in BehaviorSource.GetAllVariables())
{
behaviorTree.SetVariable(variable.Name, variable);
}
behaviorTree.EnableBehavior();
}
}
My first trouble was be able to show in the inspector the Variables that are part of the External Behavior Tree, so I've created a custom inspector:
[CustomActionEditor(typeof(BehaviorTreeExtended))]
public class CustomActionEditorTest : CustomActionEditor
{
private ExternalBehavior _externalBehavior;
public List<float> variablePosition;
public int selectedVariableIndex;
public string selectedVariableName;
public int selectedVariableTypeIndex;
public override void OnEnable()
{
variablePosition = new List<float>();
selectedVariableIndex = 0;
selectedVariableName = null;
selectedVariableTypeIndex = 0;
// Do any expensive initialization stuff here.
// This is called when the editor is created.
}
public override bool OnGUI()
{
DrawDefaultInspector();
if (!(target is BehaviorTreeExtended action) || action.ExternalBehaviorTree == null) return true;
// Dibujar datos del Behavior Tree
if (action.BehaviorSource == null || action.ExternalBehaviorTree != _externalBehavior)
{
action.BehaviorSource = action.ExternalBehaviorTree.BehaviorSource;
}
List<SharedVariable> allVariables = action.BehaviorSource.GetAllVariables();
if (allVariables != null && allVariables.Count > 0)
{
if (VariableInspector.DrawAllVariables(false, action.ExternalBehaviorTree.GetBehaviorSource(),
ref allVariables,
false,
ref variablePosition, ref selectedVariableIndex, ref selectedVariableName,
ref selectedVariableTypeIndex,
false,
true))
{
// Si no se está jugando
if (!EditorApplication.isPlayingOrWillChangePlaymode)
{
action.BehaviorSource.SetAllVariables(allVariables);
// EditorUtility.SetDirty(action.BehaviorSource); <- I should save the data here. But how? :/
}
}
}
else
{
EditorGUILayout.LabelField("There are no variables to display");
}
return true;
}
}
That shows the inspector like this:

My problem currently, is that I'm not being able to actually save the Variables values, so when I start the game, those are copied in the new component.
Also the values are lost when I change windows or reopen the project.
How can I do to save these? I'm a bit new programming inspectors.
Thank for your time!