Evaluate arbitrary mathematical expressions written as text, with variables that automatically become input ports. The Math Expression node lets you write a formula once and have it computed every frame, replacing chains of individual Math nodes with a single, readable expression.
Outputs
Port
Type
Result
float
Overview
The Math Expression node provides a full expression evaluator with support for arithmetic, comparison, logical, and bitwise operators, the ternary conditional, built-in constants, and over 35 mathematical functions. You enter the expression in the Settings tab of the Inspector. Any unrecognized identifiers in the expression are treated as variables and automatically create corresponding float input ports on the node. When the expression is evaluated each frame, the current values from those input ports are substituted into the formula.
The expression is compiled into an Abstract Syntax Tree (AST) when you type it, and this compiled form is cached for efficient per-frame evaluation. A compile status indicator in the Settings panel shows whether the expression is valid (green), empty (gray), or contains errors (red with a description of the problem). If you make a typo, existing input ports are preserved so cables are not lost while you are editing.
Expression Syntax
Operators (by precedence, lowest to highest)
Precedence
Operator
Description
Example
1
? :
Ternary conditional
x > 0 ? x : -x
2
`\
\
`
Logical OR
`a \
\
b`
3
&&
Logical AND
a && b
4
`\
`
Bitwise OR
`a \
b`
5
&
Bitwise AND
a & b
6
==!=
Equality / inequality
x == 1
7
<><=>=
Relational comparison
x >= 0
8
+-
Addition / subtraction
a + b
9
*/%
Multiplication / division / modulo
a * b % c
10
^ or **
Power (right-associative)
x ^ 2 or x ** 2
11
-!~
Unary minus, logical NOT, bitwise NOT
-x, !flag, ~bits
12
()
Parentheses / function calls
sin(x)
Constants
Name
Value
Description
pi
3.14159...
The ratio of a circle's circumference to its diameter.
Smooth thresholds: Use smoothstep for soft transitions: smoothstep(low, high, value).
Color math: Compute component values for HSL-to-RGB conversion or other color transformations.
Random variation: Add controlled randomness: baseValue + rand() * noiseAmount.
Practical Tips
Variable names must start with a letter or underscore and can contain letters, numbers, and underscores. Examples: x, myValue, _temp, input3.
Variable names are case-sensitive: Value and value create two separate input ports.
The names pi, e, true, and false are reserved constants and cannot be used as variable names. They will be replaced with their numeric values.
Function names (like sin, cos, max) are also reserved. If you use one as a variable name, it will be interpreted as a function call and cause an error if not followed by parentheses.
The operator is an alias for ^ (power). Both x 2 and x ^ 2 produce the same result.
The log function computes the common (base-10) logarithm, while ln computes the natural (base-e) logarithm. This differs from some programming languages where log means natural logarithm.
Division by zero and logarithm of non-positive numbers return 0 instead of producing errors.
If the final result is NaN or Infinity, the output is 0.
When you edit the expression and introduce a syntax error, existing input ports are preserved. This prevents cables from being disconnected while you are in the middle of editing.
Input ports appear in alphabetical order by variable name.