UProperty Reflection for FText, how do I get the localized value?

I am using a bit of code listed below to reflect on properties of a UStruct. The below works for the types I am interested in such as FString, int32, float, bool… However, when I add a FText field to my structure I am unsure on how to reflect on it, then get the localized or unlocalized value out of it. As FText does not cast to a UStrProperty.



for (TFieldIterator<UProperty> PropIt(Items.GetData()->StaticStruct()); PropIt; ++PropIt)
{
	UProperty* prop = *PropIt;
	if (dynamic_cast<UStrProperty*>(prop) != nullptr)
	{
		auto strProp = dynamic_cast<UStrProperty*>(prop);
		FString strVal = strProp->GetPropertyValue(&item);
	}
	else if (dynamic_cast<UNumericProperty*>(prop) != nullptr)
	{
		auto numProp = dynamic_cast<UNumericProperty*>(prop);
		if (numProp->IsInteger())
		{
			int32 intVal = numProp->GetSignedIntPropertyValue(&item);
		}
		else if (numProp->IsFloatingPoint())
		{
			float floatVal = numProp->GetFloatingPointPropertyValue(&item);
		}
	}
	else if (dynamic_cast<UBoolProperty*>(prop) != nullptr)
	{
		auto boolProp = dynamic_cast<UBoolProperty*>(prop);
		bool boolVal = boolProp->GetPropertyValue(&item);
	}
}


Best regards,
Justin Walsh

After a lunch break, and some more digging I’ve found the solution. There is actually an UTextProperty with the method ExportTextItem(…) that does the trick. Found the details in the Internationalization Tests module in the source.



for (TFieldIterator<UProperty> PropIt(Items.GetData()->StaticStruct()); PropIt; ++PropIt)
{
	UProperty* prop = *PropIt;
	if (dynamic_cast<UStrProperty*>(prop) != nullptr)
	{
		auto strProp = dynamic_cast<UStrProperty*>(prop);
		FString strVal = strProp->GetPropertyValue(&item);
	}
	else if (dynamic_cast<UTextProperty*>(prop) != nullptr)
	{
		auto textProp = dynamic_cast<UTextProperty*>(prop);

		FString textVal;
		textProp->ExportTextItem(textVal, &item, nullptr, nullptr, 0, nullptr);
	}
	else if (dynamic_cast<UNumericProperty*>(prop) != nullptr)
	{
		auto numProp = dynamic_cast<UNumericProperty*>(prop);
		if (numProp->IsInteger())
		{
			int32 intVal = numProp->GetSignedIntPropertyValue(&item);
		}
		else if (numProp->IsFloatingPoint())
		{
			float floatVal = numProp->GetFloatingPointPropertyValue(&item);
		}
	}
	else if (dynamic_cast<UBoolProperty*>(prop) != nullptr)
	{
		auto boolProp = dynamic_cast<UBoolProperty*>(prop);
		bool boolVal = boolProp->GetPropertyValue(&item);
	}
}