Skip to main content

ActionComponent

An abstract class in Root.Township, Alta.Intelligence.

Base for a creature action set up as a component on a creature's AI prefab. Holds the weighting and cancel rules, and builds the action with target operations found in child objects named Base Required, Base Preferred, Target Required and Target Preferred.

Constructors​

MemberWhat it is
protected ActionComponent()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

14 private and internal fields
MemberWhat it is
private IAction actionThe action built by GetStaticAction, cached so every agent shares it.
private float baseWeightingMultiplierBase part of Multiplier. 1 by default.
private bool canCancelSelfWithSameTargetBacking field for CanCancelSelfWithSameTarget. If false, picking the same action and target restarts it instead.
private int cancelPriorityBacking field for CancelPriority.
private float extraRandomMultiplierWhen above 0, a random amount up to this is added to Multiplier each time it is read.
private bool isAddingBasePreferredEditor button that adds a "Base Preferred" child object.
private bool isAddingBaseRequiredEditor button that adds a "Base Required" child object.
private bool isAddingTargetPreferredEditor button that adds a "Target Preferred" child object.
private bool isAddingTargetRequiredEditor button that adds a "Target Required" child object.
private bool isCancellableBacking field for IsCancellable. Agents don't re-pick while running an action that can't be cancelled.
private bool isUsedSet the first time the action is used, when the IAiHook components on it are initialized.
private static Logger loggerNLog logger for this class.
private int minimumCancelPriorityBacking field for MinimumCancelPriority: lowest priority a new action needs to replace this one.
private float minimumCancelWeightingBacking field for MinimumCancelWeighting: lowest weighting a new action needs to replace this one.

Properties​

MemberWhat it is
bool CanCancelSelfWithSameTarget { get; }If false, choosing this same action on the same target again restarts it instead of cancelling and starting fresh.
int CancelPriority { get; }This action is only considered while another runs if its priority is at least the running action's MinimumCancelPriority.
bool IsCancellable { get; }If false, the agent does not re-decide while this action runs; it waits for it to finish.
int MinimumCancelPriority { get; }While this action runs, other actions need at least this CancelPriority to replace it.
float MinimumCancelWeighting { get; }While this action runs, a replacement needs at least this weighting.
float Multiplier { get; }Weighting multiplier for choosing this action: the base value plus a random extra each time it is read, if set.

Events​

MemberWhat it is
event ActionSettingsUsedHandler UsedRaised each time an active action of this component starts.

Methods​

MemberWhat it is
IAction GetStaticAction()Builds the action once (with its target operations from the named child objects) and returns the cached one after that.
void HandleUsed(IActiveAction active)Called each time the action starts. On first use it initializes IAiHook components on the object, then raises Used.
protected abstract IAction GetAction()Subclasses create the IAction for this component here.
protected virtual void OnValidate()Empty editor hook for subclasses.
1 private and internal method
MemberWhat it is
private void AddChildrenTo(string childName, List<TargetOperation> operations)Adds the target operations from a named child object (such as "Base Required") to one of the action's operation lists.

Used in​

Members of other types that take, return or hold a ActionComponent: