- Vrealmatic
- Unreal Engine Wiki
- Variables
Variables in Unreal Engine
What variables can you use and how they differ from each other?

Variables in Unreal Engine
bool- boolean values (NEVER assume the size of bool).BOOLwill not compile.TCHAR- character (NEVER assume the size of TCHAR).Numerical values
Integers
intandunsigned inttypes-whose size may vary across platforms, but which is guaranteed to be at least 32 bits in width-is acceptable in code where the integer width is unimportant. Explicitly-sized types must still be used in serialized or replicated formats.Type Kind Size Range Exposed to BP int88 bit signed integer +/- 128 1 byte false uint88 bit unsigned integer 0 - 255 1 byte true int1616 bit signed "shorts" +/- 32,768 2 bytes false uint1616 bit unsigned "shorts" 0 - 65,535 2 bytes false int3232 bit signed ints +/- 2,147,483,647 4 bytes true uint3232 bit unsigned ints 0 - 4,294,967,295 4 bytes false int6464 bit signed "quad words" +/- 9,223,372,036,854,775,807 8 bytes true uint6464 bit unsigned "quad words" 0 - 18,446,744,073,709,551,615 8 bytes false PTRINTfor an integer that may hold a pointer (NEVER assume the size of PTRINT).FScalableFloat- Generic numerical value in the form Value * Curve[Level]
floatfor single precision floating point (4 bytes).doublefor double precision floating point (8 bytes).Vectors
Based on the accurancy you need, you can use the following:
Type Kind Size Range Exposed to BP FVector_NetQuantizeNormalVector (x,y,z) +/- 1 12 bytes / 2 bytes true FVector_NetQuantizeVector (x,y,z) - 0 decimal place of precision +/- 1,048,576 12 bytes / 2.5 bytes FVector_NetQuantize10Vector (x,y,z) - 1 decimal place of precision +/- 1,677,721.6 12 bytes / 3 bytes FVector_NetQuantize100Vector (x,y,z) - 2 decimal place of precision +/- 10,737,418.24 12 bytes / 3.75 bytes FVectorVector (x,y,z) - 6 decimal place of precision +/- 3.4E+38 12 bytes / 12 bytes Components- Variables can point (keep address) to any component and thus be type of anycomponent.
Text values
FName[12 bytes] - Provide a very lightweight system for using strings, where a given string is stored only once in a data tableFNamesare inherently fast, if used correctly - avoid doing ofif (ActorHasTag(TEXT("MyFNameActor_Tag"))) ...which makes temporary conversion ofFNametoFString. Use something like following, that does not make conversion, usesFNameand is roughtly 100x faster:static const FName NAME_MyFNameActor(TEXT("MyFNameActor_Tag")); if (ActorHasTag(NAME_MyFNameActor))The second code defines a static
FNameinstance namedNAME_MyFNameActor. This instance is created only once and exists for the entire runtime of the program. No need to create a new tag comparison string; instead, two internalFNameidentifiers are compared, which is faster and more memory efficient.FText[16 bytes] - Primary component for text localization - All user-facing text should use this class, as it supports text localizationFString[24 bytes] - UnlikeFNameandFText,FStringcan be searched, modified, and compared against other strings. However, these manipulations can make FStrings more expensive than the immutable string classes.
Variable type conversion
FStringtoFName:FName FStringVal = FName(*FStringVal);FStringtoint32:int32 FStringVal = FCString::Atoi(*FStringVal);FStringtofloat:float FStringVal = FCString::Atof(*FStringVal);integertoFString:FString IntString = FString::FromInt(IntVal);floattointeger:FString FloatString = FString::SanitizeFloat(floatVal);

