GOAP
GOAP copied to clipboard
Bug: Injector doesn't work correctly with GoapSetBehaviour (scriptable configs)
I have this GoapConfigInitializer for injecting logic at IActionBase etc.
public class VCDependencyInjector : GoapConfigInitializerBase, IGoapInjector
{
private IObjectResolver container;
public override void InitConfig(GoapConfig config)
{
config.GoapInjector = this;
}
[Inject]
private void Construct(IObjectResolver container)
{
this.container = container;
}
public void Inject(IActionBase action)
{
this.container.Inject(action);
}
public void Inject(IGoalBase goal)
{
this.container.Inject(goal);
}
public void Inject(IWorldSensor worldSensor)
{
this.container.Inject(worldSensor);
}
public void Inject(ITargetSensor targetSensor)
{
this.container.Inject(targetSensor);
}
}
and it won`t call from GetActions method from GoapSetFactory class from GoapSetBehaviour
private List<IActionBase> GetActions(IGoapSetConfig config)
{
var actions = this.classResolver.Load<IActionBase, IActionConfig>(config.Actions);
var injector = this.goapConfig.GoapInjector;
actions.ForEach(x =>
{
injector.Inject(x);
x.Created();
});
return actions;
}
Because GoapSetBehavior doesn't use config from GoapRunnerBehavior instead created its own GoapConfig.Default.
[DefaultExecutionOrder(-99)]
public class GoapSetBehaviour : MonoBehaviour
{
[SerializeField]
private GoapSetConfigScriptable config;
[SerializeField]
private GoapRunnerBehaviour runner;
[System.Obsolete("'Set' is deprecated, please use 'GoapSet' instead. Exact same functionality, name changed to mitigate confusion with the word 'set' which could have many meanings.")]
public IGoapSet Set { get; private set; }
public IGoapSet GoapSet { get; private set; }
private void Awake()
{
var goapSet = new GoapSetFactory(GoapConfig.Default).Create(this.config);
this.runner.Register(goapSet);
this.GoapSet = goapSet;
}
}
When I added a getter for this config at GoapRunnerBehavior and used it for GoapSetBehaviour at Awake to avoid re-creating GoapConfig as default it resolved a problem with Inject actions etc because the links to the VSDependencyInjector settings that were made in earlier are no longer lost