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
Blueprint
Const
DisplayName
Required
Required.md
Untitled.png
ref
Network
UPROPERTY
USTRUCT
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

44 lines
1.7 KiB
Markdown
Raw Normal View History

2024-10-12 17:19:46 +08:00
# Required
- **功能描述:** 指定函数的参数节点必须连接提供一个值
- **元数据类型:** bool
- **引擎模块:** Blueprint, Parameter
- **作用机制:** 在PropertyFlags中加入[CPF_RequiredParm](../../../../Flags/EPropertyFlags/CPF_RequiredParm.md)
- **常用程度:** ★★
指定函数的参数节点必须连接个变量来提供一个值。
如果参数上有提供默认值,该标志依然会忽略默认值,认为还是没提供值。还是必须要连接变量。
## 测试代码:
```cpp
//PropertyFlags: CPF_Parm | CPF_ZeroConstructor | CPF_RequiredParm | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
UFUNCTION(BlueprintCallable)
FString MyFuncTestParam_RequiredObject(UPARAM(Required) UObject* objValue);
//(CPP_Default_intValue = 123, ModuleRelativePath = Function/Param/MyFunction_TestParam.h)
//PropertyFlags: CPF_Parm | CPF_ZeroConstructor | CPF_RequiredParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
UFUNCTION(BlueprintCallable)
FString MyFuncTestParam_RequiredInt(UPARAM(Required) int intValue=123);
```
## 蓝图节点:
![Untitled](Untitled.png)
如果不连一个节点,编译时会报错:
Pin Int Value must be linked to another node (in My Func Test Param Required Int )
Pin Obj Value must be linked to another node (in My Func Test Param Required Object )
## 原理:
根据这个标记来判断。
```cpp
const bool bIsRequiredParam = Param->HasAnyPropertyFlags(CPF_RequiredParm);
// Don't let the user edit the default value if the parameter is required to be explicit.
Pin->bDefaultValueIsIgnored |= bIsRequiredParam;
```