Daily Unreal Column #77 - Custom AI focus priorities
It is very common to have our AI agents focus on either another actor or some specific location (also called focal point). Existing code does support both, but have limited amount of priorities.
If we take a peek into AIController.h file, we can find a following definition somewhere at the top:
namespace EAIFocusPriority
{
typedef uint8 Type;
const Type Default = 0;
const Type Move = 1;
const Type Gameplay = 2;
const Type LastFocusPriority = Gameplay;
}
As you can see, by default there are only 3 priorities available to us. Luckily, this isn’t an enum class but simply a typedef’ed uint8 constants. This means, that we can extend this in our game code by writing something like this:
namespace EAIFocusPriority
{
const Type CustomPriority = 3;
}
This is supported by the system as it internally expand the array that stores the focus targets for each priority:
...
if (InPriority >= FocusInformation.Priorities.Num())
{
FocusInformation.Priorities.SetNum(InPriority + 1);
}
...