Files
.obsidian
.vs
00-MOC
01-Diary
02-Note
03-UnrealEngine
Animation
Editor
Gameplay
AI
Animation
Code
Debug
GAS
Gameplay
Http
Lyra
Mass
Online
Other
PuerTS
UObject
UnrealSpecifiers
Flags
Meta
Actor
AnimationGraph
Asset
Blueprint
Component
Config
Container
Debug
DetailsPanel
Development
Enum
GAS
Material
Niagara
Numeric
Object
Path
Pin
RigVM
Scene
Script
Sequencer
Serialization
SparseDataType
String
Struct
HasNativeBreak
MakeStructureDefaultValue
MakeStructureDefaultValue.md
Untitled.png
DataflowFlesh.md
HasNativeMake.md
IgnoreForMemberInitializationTest.md
TypePicker
UHT
Widget
Meta.md
Specifier
UnrealSpecifiers.md
Ue4 c++ UProperty反射 PostEditChangeProperty.md
Ue4Object生命周期.jpg
大钊提供的一种获取UE Private函数的方法.md
LevelScene
Math
Mobile
Physical
Plugins
Rendering
Sequence
UI
VirtualProduction
VisualEffect
卡通渲染相关资料
性能优化
流程管理与部署
.keep
03-UnrealEngine.md
04-ComputerGraphics
05-SDHGame
06-DCC
07-Other
08-Assets
09-Templates
.gitattributes
.gitignore
.gitmodules
LICENSE

3.2 KiB
Raw Blame History

MakeStructureDefaultValue

  • 功能描述: 存储BP中自定义结构里的属性的默认值。
  • 使用位置: UPROPERTY
  • 引擎模块: Struct
  • 元数据类型: bool
  • 限制类型: BP里的用户自定义Struct
  • 常用程度:

存储BP中自定义结构里的属性的默认值。

  • 在C++中我们写的USTRUCT的结构里的属性默认值并不需要存储在元数据中因为在创建该结构实例的时候就自然会调用该结构的构造函数从而正确初始化值。
  • 而在蓝图中的用户自定义结构并没有构造函数之类的机制。因此我们需要一个专门的Tab来填写属性的默认值。这些默认值就会存储在属性的元数据中。

测试代码:

在蓝图中定义一个结构BP_StructDefaultTest并填上默认值。

Untitled

测试结果:

用测试命令行打印出其相关的信息可以见到MyInt和MyString的真正属性名以及MakeStructureDefaultValue 的值。

[struct BP_StructDefaultTest	UserDefinedStruct->ScriptStruct->Struct->Field->Object	/Game/Struct/BP_StructDefaultTest.BP_StructDefaultTest]
(BlueprintType = true, Tooltip = )
	ObjectFlags:	RF_Public | RF_Standalone | RF_Transactional | RF_WasLoaded | RF_LoadCompleted 
	Outer:	Package /Game/Struct/BP_StructDefaultTest
StructFlags:	STRUCT_NoFlags
Size:	24
{
	(DisplayName = MyInt, Tooltip = , MakeStructureDefaultValue = 789)
	0-[4] int32 MyInt_3_CC664A574A072369083883B38EA2F129;
		PropertyFlags:	CPF_Edit | CPF_BlueprintVisible | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash 
		ObjectFlags:	RF_Public | RF_LoadCompleted 
		Outer:	UserDefinedStruct /Game/Struct/BP_StructDefaultTest.BP_StructDefaultTest
		Path:	IntProperty /Game/Struct/BP_StructDefaultTest.BP_StructDefaultTest:MyInt_3_CC664A574A072369083883B38EA2F129
	(DisplayName = MyString, Tooltip = , MakeStructureDefaultValue = Hello)
	8-[16] FString MyString_6_D8FAF5D6454C781C2D5175ACF266C394;
		PropertyFlags:	CPF_Edit | CPF_BlueprintVisible | CPF_ZeroConstructor | CPF_HasGetValueTypeHash 
		ObjectFlags:	RF_Public | RF_LoadCompleted 
		Outer:	UserDefinedStruct /Game/Struct/BP_StructDefaultTest.BP_StructDefaultTest
		Path:	StrProperty /Game/Struct/BP_StructDefaultTest.BP_StructDefaultTest:MyString_6_D8FAF5D6454C781C2D5175ACF266C394
};

原理:

在BP中结构创建变量保存的时候如果发现默认值不为空则设置到MakeStructureDefaultValue中去。之后再MakeStruct的时候就可以用上了。

void UK2Node_MakeStruct::FMakeStructPinManager::CustomizePinData(UEdGraphPin* Pin, FName SourcePropertyName, int32 ArrayIndex, FProperty* Property) const
{
	const FString& MetadataDefaultValue = Property->GetMetaData(TEXT("MakeStructureDefaultValue"));
if (!MetadataDefaultValue.IsEmpty())
{
	Schema->SetPinAutogeneratedDefaultValue(Pin, MetadataDefaultValue);
	return;
}
}

static void FUserDefinedStructureCompilerInner::CreateVariables(UUserDefinedStruct* Struct, const class UEdGraphSchema_K2* Schema, FCompilerResultsLog& MessageLog)
{
	if (!VarDesc.DefaultValue.IsEmpty())
	{
		VarProperty->SetMetaData(TEXT("MakeStructureDefaultValue"), *VarDesc.DefaultValue);
	}
}