This document is about: QUANTUM 2
SWITCH TO

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:

  1. AI or other source of input generates desired input directly into a specific entity component
  2. Generated input can be processed later in following methods if implemented:
    1. ProcessInputDesires()
    2. PreProcessComponentDesires()
    3. PostProcessComponentDesires()
    4. Update()

The diagram below illustrates how this process is used to bypass InputDesires (priority Left => Right, Top => Bottom).

fps template specific entity input
FPS Template Specific Entity Input

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