Skip to content

Update Mode

Actions have an UpdateMode that determines how the action updates.

The settings are exposed in the editor in the Action Editor.

UpdateMode Enum

Note: Multiple update flags can be selected.

Flag Description
Every Frame Run the action every frame.
Update Run using the MonoBehaviour Update event.
FixedUpdate Run using the MonoBehaviour FixedUpdate event.
OnAnimatorMove Run using the MonoBehaviour OnAnimatorMove event.
LateUpdate Run using the MonoBehaviour LateUpdate event.
OnEventUpdate Run when the action gets an event. E. g., OnCollisionEnter.
InputEveryFrame Apply inputs every frame.
Blocking Blocks other actions from starting.
IgnorePerSecond Combines with the CanUsePerSecond property to determine if PerSecond is set.
UpdateEveryFrame A shortcut for Update and EveryFrame.
FixedUpdateEveryFrame A shortcut for FixedUpdate and EveryFrame
AllUpdates A shortcut for Update, FixedUpdate, OnAnimatorMove, and LateUpdate

UpdateMode Properties

Property Description
UpdateMode The current update mode set for the action.
DefaultUpdateMode The update mode used when creating or resetting the action.
AllowedUpdateModes Update modes that can be selected in the UI.
RequiredUpdateModes Update modes that are required by the action.
Shown as checked, but readonly in the UI.
CanFinish Boolean property that indicates if an action can finish.
CanUsePerSecond Boolean property that sets if an action has a Per Second option.

DefaultUpdateMode

Override DefaultUpdateMode to set the default update mode (default is UpdateMode.Update)

For example, if your action should typically run every frame:

public override UpdateMode DefaultUpdateMode => UpdateMode.UpdateEveryFrame;

RequiredUpdateModes

Override RequiredUpdateModes to make sure some flags are always set.

For example, it your action should always run every frame:

public override UpdateMode RequiredUpdateModes => UpdateMode.EveryFrame;

AllowedUpdateModes

The default value of AllowedUpdateModes:

public virtual UpdateMode AllowedUpdateModes => 
    UpdateMode.AllUpdates | UpdateMode.EveryFrame | UpdateMode.Blocking;

Override this if some options should be disallowed.

For example, if your action should not allow every frame:

public override UpdateMode AllowedUpdateModes => UpdateMode.AllUpdates;

PerSecond Timing

If CanUsePerSecond is true, the user can select Per Second in the Update Mode Popup:

public override bool CanUsePerSecond => true;

The setting determines the value of the PerSecond helper property that you can use as a multiplier. It will be either 1 or time.deltaTime.

PerSecond Example
public override void Execute()
{            
    Transform.Value.Translate(Translation.Value * PerSecond, RelativeTo.Value);
}

Current Mode

Actions can check the current update mode when executing using these properties:

public static UpdateMode CurrentUpdateMode { get; private set; }

protected static bool InUpdate => CurrentUpdateMode == UpdateMode.Update;

protected static bool InFixedUpdate => CurrentUpdateMode == UpdateMode.FixedUpdate;

protected static bool InLateUpdate => CurrentUpdateMode == UpdateMode.LateUpdate;

protected static bool InOnAnimatorMove => CurrentUpdateMode == UpdateMode.OnAnimatorMove;

Use these if the action needs to behave differently depending on the current update mode.