vault backup: 2024-10-12 17:19:45
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
# Const
|
||||
|
||||
- **功能描述:** 指定该函数参数不可更改
|
||||
- **元数据类型:** bool
|
||||
- **引擎模块:** Blueprint, Parameter
|
||||
- **作用机制:** 在PropertyFlags中加入[CPF_ConstParm](../../../../Flags/EPropertyFlags/CPF_ConstParm.md),在Meta中加入[NativeConst](../../../../Meta/Blueprint/NativeConst.md)
|
||||
- **常用程度:** ★
|
||||
|
||||
指定该函数参数不可更改。
|
||||
|
||||
如果在C++代码的参数上直接加const,则会自动的被UHT识别并添加CPF_ConstParm 标志,以及NativeConst元数据。但也可以手动加上UPARAM(const)来强制UHT添加CPF_ConstParm,效果见下面蓝图中的Out节点,把输出参数变成了输入参数。
|
||||
|
||||
虽然不知道什么情况下需要手动添加,因此在源码中没有找到实际的用例。能想到的用处是在蓝图层面使它变成const输入参数,但是在C++层面依然是可变的引用参数,方便在C++里调用一些非const的方法。
|
||||
|
||||
## 测试代码:
|
||||
|
||||
```cpp
|
||||
//PropertyFlags: CPF_ConstParm | CPF_Parm | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_ConstInt(UPARAM(const) int value);
|
||||
|
||||
//PropertyFlags: CPF_ConstParm | CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_ReferenceParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_ConstIntOut(UPARAM(const) int& value);
|
||||
|
||||
//(NativeConst = )
|
||||
//PropertyFlags: CPF_ConstParm | CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_ReferenceParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_ConstIntRef(UPARAM(const) const int& value);
|
||||
|
||||
//PropertyFlags: CPF_Parm | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_NoConstInt(int value);
|
||||
|
||||
//PropertyFlags: CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_NoConstIntOut(int& value);
|
||||
|
||||
//(NativeConst = )
|
||||
//PropertyFlags: CPF_ConstParm | CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_ReferenceParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_NoConstIntRef(const int& value);
|
||||
```
|
||||
|
||||
## 蓝图节点:
|
||||
|
||||
MyFuncTestParam_ConstIntOut的输出Value变成了输入的Value,因为不能改变。
|
||||
|
||||

|
||||
|
||||
## 原理代码:
|
||||
|
||||
在代码中实际出现const,就会增加CPF_ConstParam Flag。
|
||||
|
||||
```cpp
|
||||
\Engine\Source\Programs\Shared\EpicGames.UHT\Parsers\UhtPropertyParser.cs 1030
|
||||
|
||||
if (propertySettings.PropertyCategory != UhtPropertyCategory.Member && !isTemplateArgument)
|
||||
{
|
||||
// const before the variable type support (only for params)
|
||||
if (tokenReader.TryOptional("const"))
|
||||
{
|
||||
propertySettings.PropertyFlags |= EPropertyFlags.ConstParm;
|
||||
propertySettings.MetaData.Add(UhtNames.NativeConst, "");
|
||||
}
|
||||
}
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
@@ -0,0 +1,22 @@
|
||||
# DisplayName
|
||||
|
||||
- **功能描述:** 更改函数参数在蓝图节点上的显示名字
|
||||
|
||||
- **元数据类型:** string="abc"
|
||||
- **引擎模块:** Blueprint, Parameter
|
||||
- **作用机制:** 在Meta中加入[DisplayName](../../../../Meta/Blueprint/DisplayName.md)
|
||||
- **常用程度:** ★★★★★
|
||||
|
||||
注意:UPARAM也可以用在返回值上,默认值是ReturnValue。
|
||||
|
||||
## 测试代码:
|
||||
|
||||
```cpp
|
||||
//(DisplayName = My Other Name)
|
||||
UFUNCTION(BlueprintCallable)
|
||||
UPARAM(DisplayName = "My Return String") FString MyFuncTestParam_DisplayName(UPARAM(DisplayName = "My Other Name") int value);
|
||||
```
|
||||
|
||||
## 蓝图节点:
|
||||
|
||||

|
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,44 @@
|
||||
# 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);
|
||||
```
|
||||
|
||||
## 蓝图节点:
|
||||
|
||||

|
||||
|
||||
如果不连一个节点,编译时会报错:
|
||||
|
||||
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;
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
After Width: | Height: | Size: 245 KiB |
@@ -0,0 +1,45 @@
|
||||
# ref
|
||||
|
||||
- **功能描述:** 使得函数的参数变成引用类型
|
||||
|
||||
- **元数据类型:** bool
|
||||
- **引擎模块:** Blueprint, Parameter
|
||||
- **作用机制:** 在PropertyFlags中加入[CPF_ReferenceParm](../../../../Flags/EPropertyFlags/CPF_ReferenceParm.md)
|
||||
- **常用程度:★★★★★**
|
||||
|
||||
普通参数和引用参数的区别是,在获取参数的时候,Ref类型会直接获得实参的引用,而不是拷贝。这样就可以避免拷贝,保存修改。
|
||||
|
||||
单纯的&参数是会被解析成输出返回参数,因此要用ref再继续标明。
|
||||
|
||||
## 测试代码:
|
||||
|
||||
```cpp
|
||||
//PropertyFlags: CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_Default(int& refValue);
|
||||
|
||||
//PropertyFlags: CPF_Parm | CPF_OutParm | CPF_ZeroConstructor | CPF_ReferenceParm | CPF_IsPlainOldData | CPF_NoDestructor | CPF_HasGetValueTypeHash | CPF_NativeAccessSpecifierPublic
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_Ref(UPARAM(ref) int& refValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FString MyFuncTestParam_Copy(int value);
|
||||
```
|
||||
|
||||
## 蓝图的代码:
|
||||
|
||||

|
||||
|
||||
## 原理:
|
||||
|
||||
ref参数在UHT生成时会用P_GET_PROPERTY_REF来获得
|
||||
|
||||
```cpp
|
||||
#define P_GET_PROPERTY(PropertyType, ParamName) \
|
||||
PropertyType::TCppType ParamName = PropertyType::GetDefaultPropertyValue(); \
|
||||
Stack.StepCompiledIn<PropertyType>(&ParamName);
|
||||
|
||||
#define P_GET_PROPERTY_REF(PropertyType, ParamName) \
|
||||
PropertyType::TCppType ParamName##Temp = PropertyType::GetDefaultPropertyValue(); \
|
||||
PropertyType::TCppType& ParamName = Stack.StepCompiledInRef<PropertyType, PropertyType::TCppType>(&ParamName##Temp);
|
||||
```
|
Reference in New Issue
Block a user