RealDocs

FMath::Eval

function Core Since 4.0
#include "Math/UnrealMathUtility.h"
Access: public Specifiers: static

Description

Evaluates a mathematical expression from a string at runtime. Supports +, -, *, /, %, ^, &, |, unary minus, decimal and hex literals, and parentheses.

Caveats & Gotchas

  • Precedence order is: 1:+- 2:/% 3:* 4:^ 5:&| — not the standard C/C++ order. Notably * has lower precedence than / and %, which may produce surprising results for expressions like "2/3*4".
  • Only float precision is available regardless of input. Expressions that require double precision or integer semantics are not suitable.
  • This is a legacy engine utility designed for console command parsing, not a general-purpose expression evaluator. It does not support variables, functions, or whitespace in all positions — test your expression format carefully.

Signature

static CORE_API bool Eval(FString Str, float& OutValue)

Parameters

Name Type Description Default
Str FString String containing the mathematical expression to evaluate.
OutValue float& Receives the computed float result if the function returns true.

Return Type

bool

Example

Parse a numeric expression entered via console command C++
float Result;
if (FMath::Eval(TEXT("(3 + 4) * 2"), Result))
{
    UE_LOG(LogTemp, Log, TEXT("Result: %f"), Result); // 14.0
}
else
{
    UE_LOG(LogTemp, Warning, TEXT("Failed to evaluate expression"));
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.