Behavior parameter

From AI Product Manuals
Jump to navigationJump to search
This page is part of the IAUS Manual.BrainBehaviorBehavior TypeDecisionAI Entity

This item is a component of a Behavior.


A Behavior Parameter is attached to a Behavior to help define specific things that behavior needs to execute. Some of them are booleans about whether or not something should occur. For example, specifying an arrival distance to a location or target that the character will be moving to, or whether the behavior should reset where the character is looking or facing when it it executes. Others can be used to pass data into the execution of the behavior. If an action is supposed to place a tag onto a target agent, for instance, the specific tag to be applied can be held in the appropriate behavior parameter.

While there are some built-in behavior parameters from the start (with their relevant code), they can be added to—both in data and with the relevant code for how it is executed—in order to support game-specific things.



The list of available Behavior Params is held in the enums file as BehaviorParameterType.

enum class BehaviorParamType
	ThinkDelay = 1,		// How long to wait before thinking after performing this action. (Good for completing animations.)
	StopMovement = 2,		// Should this behavior stop any existing movement? (1 or 0 for boolean equivalent.)
	ArrivalDistance = 3,		// What is the distance to use for "arrival"?
	SetLooking = 4,		// Set head looking. (0=No change, 1=target, 2=self orient)

Behavior Parameters are stored in the Behavior themselves in a sparse data construct (Dictionary in C# or unordered_map in C++). For readability, these are defined in a typedef, "BehaviorParamMap".

typedef std::unordered_map<BehaviorParamType, float> BehaviorParamMap;

They are contained in the Behavior class as "behaviorParams". (Note this must exist in both the IBehavior interface as well as the Behavior class itself.)

BehaviorParamMap behaviorParams;

They are accessed by a function that checks to see if it exists in that behavior's parameters and, if not, returns a default.

virtual float GetParameterOrDefault(BehaviorParamType thisParamType, float thisDefault);

These checks are often performed in individual functions for readability and called from the SetupBehavior function at the start of execution of each behavior.

void Behavior::SetupBehavior(ContextInfo* thisContext)

Using simply the first one in that example list, this is a simple Boolean check for the parameter to see if the behavior should force the stoppage of moment.

void Behavior::StopMovementIfDesignated(ContextInfo* thisContext)
	bool shouldStop = GetParameterOrDefault(&behaviorParams, BehaviorParamType::StopMovement, 0.0);
	if (shouldStop)

Note that the default is 0.0 if it doesn't find the parameter. This is a way of making this check return false if the parameter is not added. Because of this, there is no need to put the parameter into a behavior if is meant to be false.


New Behavior Parameters are added from the main in the Data Tool. At that point, the appropriate handler needs to be created in the code for it to work.

Existing Behavior Parameters are added to a Behavior as necessary in the data tool as well on the page for the specific behavior. Remember that because the data is sparse, do not add a parameter to a behavior unless it is needed.

The entry in the tool will specify which parameter type you are using and a value for that parameter. For things that are Boolean-like, you will enter a 1 or a 0. Note that if the code states that, if there is no parameter entry for that parameter type, it should return a default of 0, then you do not need to enter the parameter with a value of 0. The assumption is that if it is not entered, then it is false.