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
Specifier
UCLASS
UENUM
UFUNCTION
UINTERFACE
UPARAM
UPROPERTY
USTRUCT
Blueprint
Serialization
UHT
Atomic
NoExport
HasDefaults.md
HasNoOpConstructor.md
IsAlwaysAccessible.md
IsCoreType.md
UCLASS.md
UENUM.md
UFUNCTION.md
UINTERFACE.md
UPARAM.md
UPROPERTY.md
USTRUCT.md
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
BlueRoseNote/03-UnrealEngine/Gameplay/UObject/UnrealSpecifiers/Specifier/USTRUCT/UHT/HasNoOpConstructor.md

61 lines
2.0 KiB
Markdown
Raw Normal View History

2024-10-12 17:19:46 +08:00
# HasNoOpConstructor
- **功能描述:** 指定该结构拥有ForceInit的构造函数这样在作为BP function返回值的时候可以调用来初始化
- **元数据类型:** bool
- **引擎模块:** UHT
- **限制类型:** 只在NoExportTypes.h供UHT使用
- **常用程度:** 0
指定该结构拥有ForceInit的构造函数这样在作为BP Function返回值或参数的时候引擎就知道这个结构有这么一个构造函数可以调用来初始化。
作用的地方是UhtHeaderCodeGenerator中的AppendEventParameter为了这样的代码这是一个暴露到BP中的Event要为它生成一些胶水代码。这里FLinearColor 就是HasNoOpConstructor。例如以下这个函数
```cpp
UFUNCTION(BlueprintNativeEvent, Category = "Modifier")
FLinearColor GetVisualizationColor(FInputActionValue SampleValue, FInputActionValue FinalValue) const;
```
生成的代码:
```cpp
struct InputModifier_eventGetVisualizationColor_Parms
{
FInputActionValue SampleValue;
FInputActionValue FinalValue;
FLinearColor ReturnValue;
/** Constructor, initializes return property only **/
InputModifier_eventGetVisualizationColor_Parms()
: ReturnValue(ForceInit)//强制初始化
{
}
};
static FName NAME_UInputModifier_GetVisualizationColor = FName(TEXT("GetVisualizationColor"));
FLinearColor UInputModifier::GetVisualizationColor(FInputActionValue SampleValue, FInputActionValue FinalValue) const
{
InputModifier_eventGetVisualizationColor_Parms Parms;
Parms.SampleValue=SampleValue;
Parms.FinalValue=FinalValue;
const_cast<UInputModifier*>(this)->ProcessEvent(FindFunctionChecked(NAME_UInputModifier_GetVisualizationColor),&Parms);
return Parms.ReturnValue;
}
```
因此要求该结构拥有ForceInit的构造函数
```cpp
FORCEINLINE explicit FLinearColor(EForceInit)
: R(0), G(0), B(0), A(0)
{}
```
## 原理:
```cpp
if (ScriptStruct.HasNoOpConstructor)
{
//If true, the an argument will need to be added to the constructor
PropertyCaps |= UhtPropertyCaps.RequiresNullConstructorArg;
}
```