Search code examples
c++unreal-engine4

How to convert FText to float in UE4


I'm getting user input from a box in the unreal engine landscape import pane and would like to be able to convert that input to a float. Currently, the text comes in as FText

I've tried casting the resulting FText to float and using the built-in FText::toNumber.

I would like to be able to do something like:

FText mapDeltaX = GetPropertyValueText(PropertyHandle_Scale_X);
float deltaX = (float)mapDeltaX;

But unfortunately I get the error no suitable conversion from "FText" to "float" exists.


Solution

  • You can convert TCHAR* to float using

    FCString::Atof(*String);
    

    So in your case you'd convert your FText to FString, then to float:

    FCString::Atof(*mapDeltaX.ToString());