Specific Entity Input
To support specific entity inputs -e.g. an AI HFSM provides a specific EntityRef
target based on the state-, it is not efficient solution to store all inputs inside InputDesires
as this would lead to an explosion in memory requirements. This can be done by:
- AI or other source of input generates desired input directly into a specific entity component
- Generated input can be processed later in following methods if implemented:
ProcessInputDesires()
PreProcessComponentDesires()
PostProcessComponentDesires()
Update()
The diagram below illustrates how this process is used to bypass InputDesires
(priority Left => Right, Top => Bottom).
Example of generating attack target input for spider entity inside HFSM action:
C#
[Serializable]
public unsafe sealed class SetSpiderAttackTargetAIAction : AIAction
{
public AIBlackboardValueKey ReferenceKey;
public override void Update(Frame frame, EntityRef entity)
{
if (ReferenceKey.Key.HasValue() == false)
{
Log.Warn($"Missing ReferenceKey {frame.EntityContext.CurrentHFSMState.Label} {nameof(SetSpiderAttackTargetAIAction)}");
return;
}
frame.GetComponent<Spider>(entity)->AttackTarget = frame.EntityContext.AIBlackboard->GetEntityRef(frame, ReferenceKey.Key);
}
}
and one of its possible processing ways in SpiderController
:
C#
public unsafe class SpiderController : UpdatableActorController, IEntityInitializer, IInputController, IPreProcessComponentDesiresController, IDeathController
{
...
internal override void Update(Frame frame, EntityRef entity)
{
Spider* spider = frame.GetComponent<Spider>(entity);
if (spider->AttackTarget != EntityRef.None)
{
TryAttack(frame, spider->AttackTarget);
}
}
...
}
Back to top