Expression Actions
PlayMaker 2 includes powerful Expression Evaluator actions that let you calculate numeric and boolean results directly from text expressions.
Expressions can include:
- Numbers and math operators
- FSM variables using
{}braces - Built-in Unity values like
Time.deltaTime - Supported math functions such as
Sin(),Cos(), andSqrt() - Comparisons and boolean logic
- String comparisons such as
==,!=,===,~,^=, and$=
Expression Evaluator Actions
Evaluate a mathematical expression and store the result in a float variable.
Evaluate a mathematical expression and store the result in an integer variable.
Evaluate a mathematical expression and store the result in a long variable.
Evaluate a mathematical expression and store the result in a double variable.
Evaluate a boolean expression and optionally store the result or send true and false events.
Numeric Expressions
Supported Syntax
Numeric expressions use the same rules as Unity's ExpressionEvaluator:
| Operator | Description | Example |
|---|---|---|
+ |
Addition | 2 + 3 |
- |
Subtraction | {Health} - 10 |
* |
Multiplication | {Speed} * 2 |
/ |
Division | {Distance} / {Time} |
% |
Modulo | {Score} % 10 |
^ |
Power | 2 ^ 3 -> 8 |
() |
Parentheses | (1 + 2) * 3 |
Supported Math Functions
MathExpressionUtility currently supports these functions (beta 83+):
| Function | Parameters | Description |
|---|---|---|
Abs |
1 | Absolute value. |
Acos |
1 | Arc cosine. |
Asin |
1 | Arc sine. |
Atan |
1 | Arc tangent. |
Atan2 |
2 | Arc tangent from y and x values. |
Ceil |
1 | Round up to the nearest whole number. |
Ceiling |
1 | Alias for Ceil. |
Clamp |
3 | Clamp a value between minimum and maximum. |
Cos |
1 | Cosine. |
Exp |
1 | Exponential function. |
Floor |
1 | Round down to the nearest whole number. |
Log |
1 | Natural logarithm. |
Log10 |
1 | Base-10 logarithm. |
Max |
2 | Return the larger of two values. |
Min |
2 | Return the smaller of two values. |
Pow |
2 | Raise a value to a power. |
Round |
1 | Round to the nearest whole number. |
Sign |
1 | Return -1, 0, or 1 based on the sign. |
Sin |
1 | Sine. |
Sqrt |
1 | Square root. |
Tan |
1 | Tangent. |
Expressions are evaluated with double precision, then cast to the target type (
Float,Int,Long, and so on) depending on the action.
Variables and Placeholders
Basic Usage
Variables are inserted using {} braces:
Braces are required to clearly distinguish variable names from function names.
Property Access
You can access properties of common Unity types:
| Type | Supported Properties |
|---|---|
| Vector2 / Vector3 / Vector4 | .x .y .z .w .magnitude .sqrMagnitude |
| Color | .r .g .b .a |
| Quaternion | .x .y .z .w .eulerX .eulerY .eulerZ |
| Rect | .x .y .width .height |
| Bounds | .center .size .extents and .x/.y/.z on those vectors |
| Transform | .position .localPosition .eulerAngles .localEulerAngles .lossyScale .forward .up .right .childCount |
| GameObject | .transform |
| Owner | The FSM's owner GameObject, for example {Owner.transform.position.y} |
Built-in Values
You can use Unity's built-in time values, with or without braces:
| Name | Description |
|---|---|
Time.deltaTime |
Time since last frame |
Time.time |
Time since startup, scaled |
Time.unscaledTime |
Real time since startup, unscaled |
Boolean Expressions
Boolean expressions evaluate to true or false and support both numeric and string comparisons.
Comparison Operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
> |
Greater than | {Health} > 50 |
True if health > 50 |
< |
Less than | {Speed} < 10 |
True if speed < 10 |
>= |
Greater or equal | {Score} >= 1000 |
True if score >= 1000 |
<= |
Less or equal | {Ammo} <= 0 |
True if ammo <= 0 |
== |
Equal, case-insensitive by default | {Name} == "Alex" |
True if equal |
!= |
Not equal | {State} != "Dead" |
True if not equal |
=== |
Equal, case-sensitive | {Name} === "Alex" |
True only if exact case matches |
!== |
Not equal, case-sensitive | {Name} !== "alex" |
True if case differs |
~ |
String contains | {Title} ~ "Engineer" |
True if substring is found |
^= |
String starts with | {Email} ^= "alex." |
True if prefix matches |
$= |
String ends with | {Email} $= "@hutonggames.com" |
True if suffix matches |
Logical Operators
| Operator | Meaning | Example |
|---|---|---|
&& |
AND | {Health} > 50 && {Ammo} > 0 |
\|\| |
OR | {Dead} \|\| {Health} <= 0 |
! |
NOT | !{IsGrounded} |
Parentheses
Use parentheses to group conditions:
Evaluation Rules
Variable Resolution
{}braces indicate FSM variables.- Dotted property paths are resolved step-by-step, for example
{Transform.position.y}. - Missing or invalid values return
0.
Type Handling
| Type | Converted To | Example |
|---|---|---|
bool |
1 for true or 0 for false | {IsVisible} |
int, float, double, long |
Numeric | {Speed} |
Vector2/3/4 |
Magnitude | {Velocity} |
Color |
Grayscale average | {Color} |
| Non-numeric object | 0 | {GameObject} |
Examples
Numeric Examples
Boolean Examples
{Health} > 0 && !{IsDead}
({Score} >= 1000 && {Lives} > 0) || {Invincible}
{Name} == "Alex" || {Title} ~ "Developer"
{Email} $= "@hutonggames.com" && {Active}
Mixed Examples
({Position.y} < 0 && {Velocity.y} < 0) || {Grounded}
{Owner.transform.position.y} > 1.0
{Direction.magnitude} > 0.1 && {Speed} <= {MaxSpeed}
Error Handling
- If an expression fails or a variable is missing,
Succeededis set tofalse. - Failed evaluations default the result to
0orfalse. - Division by zero returns
0and fails the evaluation. - Invalid property paths such as
{Position.foo}return0and log a warning.
Tips
- Keep expressions short and readable. For complex logic, split the work into multiple actions.
- Use parentheses to clarify order of operations.
- Use Evaluate Boolean Expression when comparing strings or combining logic.
- Use the action list on this page to pick the result type you want to store.
Quick Reference
| Category | Syntax | Description |
|---|---|---|
| Math | + - * / % ^ () |
Standard operators |
| Functions | abs acos asin atan atan2 ceil ceiling clamp cos exp floor log log10 max min pow round sign sin sqrt tan |
Supported numeric functions |
| Variables | {Name} |
FSM variable |
| Properties | {Transform.position.x} |
Access sub-fields |
| Built-ins | Time.deltaTime, Time.time, Time.unscaledTime |
Unity time values |
| Comparison | > < >= <= == != === !== |
Numeric and string equality |
| String ops | ~ ^= $= |
contains / startsWith / endsWith |
| Logic | && \|\| ! |
AND / OR / NOT |
| Parentheses | ( ) |
Group expressions |
| Result Types | double / bool | Returns numeric or boolean |
| Failure | Returns 0 / false |
Sets Succeeded = false |