Conditions¶
A condition is a requirement that gates an Action. When the Action would normally complete, its conditions are checked first: if they are all satisfied the Action performs as usual, otherwise the Action is held back (or failed).
Conditions never drive an Action. They only decide whether the Action is allowed to perform when its own interaction has already been fulfilled. For example, an Insert Action still needs the user to insert the object; a condition can additionally require that it happened within a time limit.
Adding a condition¶
Every Action node has a conditions button in its header. Pressing it opens the Conditions panel, which lists the conditions of that Action and offers an Add condition dropdown with every available condition type. Press X on a row to remove it.
Each row is a foldout, titled with the condition’s Description (or its type name when the description is empty).
Common parameters¶
All conditions share the following parameters, drawn at the top of the row:
Parameter name |
Explanation |
|---|---|
Fail |
When the check is not satisfied, fail the Action instead of just halting it. A halted Action simply stays running, so the user can try again; a failed Action reports an error to the user through the notification system. |
Negate |
Invert the check: pass when it is false, halt/fail when it is true. Useful to express “must not …” without a second condition type. |
Critical |
Only has an effect together with Fail, and stays greyed out until Fail is enabled. A critical failure invalidates the whole operation: the graph stops advancing and the user is prompted to restart. |
Description |
The message shown to the user when this condition fails. Also used as the row title in the editor. Leave it empty to get a generic message. |
The rest of the parameters depend on the condition type.
Possible outcomes¶
Outcome |
What happens |
|---|---|
Pass |
The Action performs and the graph moves on. |
Halt |
The Action does not perform and stays running. Nothing is reported. The check runs again the next time the Action is triggered. |
Fail ( |
The Action does not perform, and an error notification with the condition’s description is shown to the user. |
Critical fail ( |
As above, but the graph is stopped and the user is prompted to restart the operation. |
When an Action has several conditions, all of them are checked and the worst outcome wins - so multiple conditions behave like a logical AND. The condition that produced that worst outcome is the one whose description is shown to the user.
Below is a table that describes each possible outcome when combining results from conditions to illustrate this:
Result 1 |
Result 2 |
Outcome |
|---|---|---|
Pass |
Pass |
Pass |
Pass |
DontPass |
DontPass |
Pass |
Fail |
Fail |
Pass |
CriticalFail |
CriticalFail |
DontPass |
Pass |
DontPass |
DontPass |
DontPass |
DontPass |
DontPass |
Fail |
Fail |
DontPass |
CriticalFail |
CriticalFail |
Fail |
Pass |
Fail |
Fail |
DontPass |
Fail |
Fail |
Fail |
Fail |
Fail |
CriticalFail |
CriticalFail |
CriticalFail |
Pass |
CriticalFail |
CriticalFail |
DontPass |
CriticalFail |
CriticalFail |
Fail |
CriticalFail |
CriticalFail |
CriticalFail |
CriticalFail |
Lifecycle¶
Stage |
When it runs |
|---|---|
|
When the Action initializes, before its interaction is set up. This is where a condition resolves references, spawns helper objects or starts timers. |
|
Every time the Action is triggered. This is a snapshot taken at that moment, not a continuous evaluation. |
|
When the Action is undone, or when the graph shuts down. Anything created in
|
Note
An Action can be re-initialized while it is still running (Group, Repeat and the
flow nodes do this). In that case the condition is undone first, so it never sets up on top of
itself.
Built-in conditions¶
Condition |
Explanation |
|---|---|
Action Completion |
Passes if the referenced Action has been performed. Use it to require an optional or parallel Action to be done before this one is allowed to complete. |
Question Answer |
Passes based on the answer submitted to a Question Action - any correct answer, any incorrect answer, or one specific answer index. |
Time Limit |
Passes if the Action was completed within the configured limit (minutes + seconds). The limit is only sampled when the Action is triggered, so an Action that is never completed never fails on its own. Negate it to express “must take at least”. |
Use Interactable At |
Passes if the referenced object is inside a Location volume and, optionally, activated. See the tutorial for a full walkthrough. |
Writing your own condition¶
Derive from ConditionData, mark it [System.Serializable], and override the stages you
need. Your public serialized fields appear in the Conditions panel automatically, and the type
shows up in the Add condition dropdown with a human readable name (ConditionData is
stripped and the remaining words are split, so MyToolIsCleanConditionData becomes
My Tool Is Clean).
using MAGES;
using UnityEngine;
[System.Serializable]
public class UserIsCrouchingConditionData : ConditionData
{
[Tooltip("The height, in meters, below which the user counts as crouching.")]
[SerializeField]
public float maxHeight = 1.2f;
// Data gives you the Action this condition is attached to.
public override bool Check()
{
return Camera.main.transform.position.y < maxHeight;
}
}
Hint
Check is expected to answer a simple “is the requirement met” question. The Fail,
Negate and Critical flags are applied on top of whatever you return, so do not
handle them yourself.
Warning
If a condition cannot resolve its references, the built-in conditions log a warning and pass rather than blocking the user. Follow the same rule in your own conditions: a misconfigured condition should never make a simulation impossible to finish.