FName constructor

I’m not sure why the internal code writes:

FName(TEXT("AILineOfSight"))

instead of:

FName("AILineOfSight")

Which one is better and why? FName has many constructors but why bother with TEXT("") when it is not required? I can not find a performance difference either.

I do know that the code below is bad according to the documentation ( FName | Unreal Engine Documentation ):

FString Foo = "foo";
FName(*Foo )

But there is no mention of:

FName("Foo")

After a search in the internal code it seems that the Epic developers sometimes use FName("") and sometimes use FName(TEXT("")) at random…

If you do not specify the TEXT() macro, your literal will be encoded using ANSI, which is highly limited in what characters it supports. Any ANSI literals being passed into FString need to undergo a conversion to TCHAR (native Unicode encoding), so it is more efficient to use TEXT().

It is worth noting though that FName will store strings containing only ANSI characters as ANSICHAR rather than a WIDECHAR, so if your literal string only contains ANSI characters, then not using TEXT(...) with an FName will allow it to skip that narrowing check and conversion.

What you’ve said is perfectly correct and valid for FString though, which always stores its data as a TCHAR (which is WIDECHAR by default).