To create a Math Expression node, Right-click in the graph and select Add Math Expression... from the context menu.
The Math Expression node acts like a collapsed graph. It is a single node that you can Double-click to open the sub-graph that makes up its functionality.
Initially, the name/expression is blank. Whenever you rename the node, then the new expression is parsed and a new sub-graph is generated.
To rename the node and update the sub-graph, Right-click on the node and select Rename.
For example, you could rename the Math Expression node with the following expression:
This would update the Math Expression node to have two float inputs, X and MyVar, and one float output.
If you Double-click the node with this expression, you would see the below sub-graph:
Click image for full size.
The sub-graph is created by following the below rules:
- Alphabetic names (tokens beginning with a letter) should be turned into either variables, input pins on the Math Expression node, or function calls. From the example above: x, sin, myVar, and rand.
- If an alphabetic name matches an existing variable in the Blueprint, then it will become a variable get node (i.e. if the Blueprint already had a myVar variable).
- If an alphabetic name is followed by an open parenthesis, like sin( and rand(, then it will be turned into a function node.
- If the previous two states are not met, then the alphabetic name is turned into a float input on the Math Expression node.
- The name will also be used as an input if it matches the name of an existing pin on the node.
- Numerical constants are always turned into pin inputs. They never create a node themselves, but instead are used to fill out input fields on other nodes.
- Mathematical operators (like +, *, -) are turned into function nodes.
- Like in mathematics, expressions inside of parentheses will take precedence, and be evaluated first.