Unreal Engine 5 · Blueprint → C++
Convert String To Number in Unreal Engine 5 C++UE Docs
To parse a string into a number in Unreal Engine 5 C++, use FCString::Atoi for integers and FCString::Atof for floats, dereferencing the FString to a TCHAR* first.
Blueprint node & C++ equivalent
int32 AsInt = FCString::Atoi(*MyString);
float AsFloat = FCString::Atof(*MyString);The C++ equivalent of String To Number
FCString::Atoi(*MyString) parses a string into an int32, and FCString::Atof(*MyString) parses it into a float. The * operator converts the FString into the const TCHAR* that these C-style parsing functions require. This mirrors the Blueprint string-to-int and string-to-float conversion nodes.
How to use it in C++
Pass the dereferenced string directly: int32 AsInt = FCString::Atoi(*MyString);. These functions stop parsing at the first non-numeric character and return 0 if the string does not begin with a valid number, so they do not throw on malformed input. For stricter validation, check the string contents or use FString::IsNumeric before parsing.
Common mistakes
Forgetting the * dereference is a frequent error, since FCString::Atoi expects a raw TCHAR*, not an FString. Also remember that invalid input silently returns 0 rather than signaling an error, so validate user-entered strings if a zero result is ambiguous.
Frequently asked questions
How do you convert a string to an int in UE5 C++?+
Call FCString::Atoi(*MyString). The * dereferences the FString to a TCHAR*, and the function returns the parsed int32.
How do you convert a string to a float in Unreal Engine 5?+
Use FCString::Atof(*MyString), which returns a float. As with Atoi, dereference the FString with * so it passes as a TCHAR*.
What does FCString::Atoi return for an invalid string?+
It returns 0 if the string does not start with a valid number. Validate input with FString::IsNumeric first if a zero result would be ambiguous.