Featured image of post [UE5] 構造体やクラスの名前に付いている接頭辞 'F' の意味

[UE5] 構造体やクラスの名前に付いている接頭辞 'F' の意味

UE 5.1.1 (UE 4.27.2)

はじめに

Unreal Engine では、構造体やクラスの名前に適切な接頭辞を付けることが求められます。

接頭辞は大文字のアルファベット 1 文字ですが、

  • AActor 継承 class には ‘A’ を付ける
  • template class には ‘T’ を付ける

というように、基本的には「接頭辞が何の略か」が推測しやすいルールになっています。

では、FStringFTransform などに付いている接頭辞 ‘F’ は、一体何の略なのでしょうか?

接頭辞 ‘F’ の意味

接頭辞 ‘F’ の意味については、Epic Games のスタッフである Michael_Noland 氏が公式フォーラムで回答しています。

(Michael_Noland | 2014/04/02 02:56)

F started with FVector as a vector of floats, but for one reason or another it’s now the prefix for all structs (required for any reflected USTRUCT(), optional for non-reflected structs but part of our coding standard).

std math function ? - Programming & Scripting / C++ - Epic Developer Community Forums

その後、同じく Epic Games のスタッフである Dark-Veil 氏も、この件について公式フォーラムに “Unreal trivia” として投稿しています。

(Dark-Veil | 2015/02/26 06:58)

The ‘F’ prefix actually stands for “Float” (as in Floating Point.)

Tim Sweeney wrote the original “FVector” class along with many of the original math classes, and the ‘F’ prefix was useful to distinguish from math constructs that would support either integers or doubles, even before such classes were written. Much of the engine code dealt with floating point values, so the pattern spread quickly to other new engine classes at the time, then eventually became standard everywhere.

Unreal trivia: What does the ‘F’ prefix on classes and structs stand for? - Programming & Scripting / C++ - Epic Developer Community Forums

(後者は他のスタッフから「もうその話は 10 ヶ月前にしたよ 😛」とツッコまれていてかわいそう 😭)

要約すると、

  • 接頭辞 ‘F’ は元々は “Float” の略
  • 接頭辞 ‘F’ が最初に付けられたのは FVector
    • 「要素 (x, y, z) の型が単精度浮動小数点数型 (float) である」ということを明示するために付けられた
  • どういうわけか、float とは関係がない構造体やクラスにもこの接頭辞が使われるようになり、現在に至る

とのことです。

余談 : FVector の現在

FVector は今でも利用されている構造体ですが、UE5 にて Large World Coordinates (LWC) が導入された影響で、要素の型が単精度浮動小数点数型 (float) から倍精度浮動小数点数型 (double) に変更されています。

試しに、UE 4.27.2 と UE 5.1.1 で、要素 X のサイズ を Log 出力してみます。単位は Byte です。

1
UE_LOG(LogTemp, Log, TEXT("sizeof(FVector().X) = %u"), static_cast<uint32>(sizeof(FVector().X)));

結果がこちら。

LogTemp: sizeof(FVector().X) = 4
LogTemp: sizeof(FVector().X) = 8

UE 5.1.1 では倍精度になっていることがわかります。

つまり、「接頭辞 ‘F’ の起源となった FVector でさえも、今では float とは関係なくなってしまった」ということになります。なんだかちょっとかなしい……。

( ´•̥ ω •̥` )<おわり

参考