Skip to content

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 (Time.deltaTime, etc.)
  • Function calls (e.g., sin(), cos(), sqrt())
  • Comparisons and boolean logic
  • String comparisons (==, !=, ===, ~, ^=, $=, etc.)

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 ^ 38
() Parentheses (1 + 2) * 3

Functions

Unity’s ExpressionEvaluator supports most common math functions:

Function Description Example
sin(x) / cos(x) / tan(x) Trigonometric functions sin({Angle})
asin(x) / acos(x) / atan(x) Inverse trig acos(0.5)
sqrt(x) Square root sqrt({Distance})
abs(x) Absolute value abs({Offset})
min(a,b) / max(a,b) Min / Max max({A}, {B})
clamp(x,min,max) Clamp clamp({Speed},0,10)
pow(a,b) Power pow(2,8)
exp(x) / log(x) Exponential / Logarithm log({Value})
sign(x) -1, 0, 1 depending on sign sign({Velocity})
round(x) / floor(x) / ceil(x) Rounding round({Health})
random(min,max) Random float random(0,100)

⚙️ Expressions are evaluated with double precision, then cast to the target type (Float, Int, Long, etc.) depending on the action.


Variables and Placeholders

Basic Usage

Variables are inserted using {} braces:

{Health} / {MaxHealth} * 100

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 - e.g. {Owner.transform.position.y}

Built-in Values

You can use Unity’s built-in time values (braces optional):

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 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:

({Health} > 50 && {Ammo} > 0) || {PowerUpActive}

Evaluation Rules

Variable Resolution

  1. {} braces indicate FSM variables.
  2. Dotted property paths are resolved step-by-step (e.g. {Transform.position.y}).
  3. Missing or invalid values return 0.

Type Handling

Type Converted To Example
bool 1 (true) or 0 (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

({Health} / {MaxHealth}) * 100
{Speed} * Time.deltaTime
max({A}, {B}) + sqrt({Value})

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:
    • Succeeded is set to false
    • The result defaults to 0 or false
  • Division by zero returns 0 and fails the evaluation.
  • Invalid property paths (e.g., {Position.foo}) return 0 and log a warning.

Tips

  • Keep expressions short and readable - for complex logic, use multiple actions.
  • Use parentheses to clarify order of operations.
  • Test expressions using Expression Evaluator → Test Value actions.
  • Use Boolean Expression actions when comparing strings or combining logic.

Quick Reference

Category Syntax Description
Math + - * / % ^ () Standard operators
Functions sin cos tan sqrt abs min max clamp pow log exp sign round floor ceil random 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 / 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