執筆バージョン: Unreal Engine 4.27.2
|
Unreal Engine 5.0.0 Preview 2
|
皆さんこんにちは。エンジニアの森です。
今回は、サンプルプロジェクト「ShowFriendlyPropertyNames」という隠れ設定を紹介します。
デフォルトの挙動
まずはこちらをご覧ください。プロジェクトのパッケージング設定です。

では、こちらの「Additional Non-Asset Directories to Package」設定をソースコードで検索してみます。

こちらが見つかりました
ファイルパスは「\UE4\Engine\Source\Editor\UnrealEd\Classes\Settings\ProjectPackagingSettings.h」です。
「DirectoriesToAlwaysStageAsUFS」変数に UPROPERTY で meta 属性 “DisplayName” が設定されています。
次に、Config フォルダや Saved フォルダ内の .ini ファイル群から「Additional Non-Asset Directories to Package」を検索しようとしても、何も見つかりません。
この Display Name はエディターでのみ有効な値であり、.ini ファイルには生の変数名が使用されているからです。
つまり、さきほどの「DirectoriesToAlwaysStageAsUFS」で検索する必要があります。
すぐに「DefaultGame.ini」の中にこちらが見つかりました。

現状、エディターのプロジェクト設定と、実際の .ini ファイルの記述が異なるため、混乱を招く恐れがあります。
また、表示されるままの名前で検索しても見つからないという不便を抱えています。
これを解消するための設定が「ShowFriendlyPropertyNames」です。
設定する
プロジェクトの Config にこちらを配置します
|
[PropertySettings] ShowFriendlyPropertyNames=False |
次にエディターを開くと、Project Setting の表示名が生の変数名になっています。

この名前は全て、.ini ファイルに直接記述されます。
これで、プロジェクト設定と .ini ファイルの行き来を少し便利にできました。
自分のデータアセット等も設定は適用されます。
ただし、この設定を入れるとエディター上で meta で設定されている Display Name による検索は行えなくなります。
今までの Display Name に慣れている方は、使う前に良く吟味してください。
なお、こちらの設定は「PropertyNode.cpp」に記述されています。
これは、Unreal Engine 5.0.0 Preview 2 でも同じです。

|
FPropertySettings::FPropertySettings() : bShowFriendlyPropertyNames( true ) , bExpandDistributions( false ) , bShowHiddenProperties(false) { GConfig->GetBool(TEXT("PropertySettings"), TEXT("ShowHiddenProperties"), bShowHiddenProperties, GEditorPerProjectIni); GConfig->GetBool(TEXT("PropertySettings"), TEXT("ShowFriendlyPropertyNames"), bShowFriendlyPropertyNames, GEditorPerProjectIni); GConfig->GetBool(TEXT("PropertySettings"), TEXT("ExpandDistributions"), bExpandDistributions, GEditorPerProjectIni); bShowFriendlyPropertyNames = false; } |
他にも、「ShowHiddenProperties」や「ExpandDistributions」といった項目がありますが、こちらの挙動は調べていません。
4.27 エディターの BaseEditorPerProjectUserSettings.ini の値は以下の表の通り
ShowHiddenProperties |
記述なし(False) |
ShowFriendlyPropertyNames |
True |
ExpandDistributions |
False |
おまけ
UMetaData::SetValue()関数を改造すれば、プロパティだけでなくEnumの値や関数名の Display Name も無効にできます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void UMetaData::SetValue(const UObject* Object, FName Key, const TCHAR* Value) { check(Key != NAME_None); if (!HasAllFlags(RF_LoadCompleted)) { UE_LOG(LogMetaData, Error, TEXT("MetaData::SetValue called before meta data is completely loaded. %s'"), *GetPathName()); } // look up the existing map if we have it TMap<FName, FString>* ObjectValues = ObjectMetaDataMap.Find(Object); // if not, create an empty map if (ObjectValues == NULL) { ObjectValues = &ObjectMetaDataMap.Add(const_cast<UObject*>(Object), TMap<FName, FString>()); } // set the value for the key //========追加======== const FString DisplayNameKey = TEXT("DisplayName"); if (Key == *DisplayNameKey) { ObjectValues->Add(Key, Object->GetName()); return; } else if (Key.ToString().EndsWith(DisplayNameKey)) { ObjectValues->Add(Key, Key.ToString().LeftChop(DisplayNameKey.Len() + 1)); return; } //========追加======== ObjectValues->Add(Key, Value); } |
動作イメージ


以上、ありがとうございました。