44 lines
1.4 KiB
Markdown
44 lines
1.4 KiB
Markdown
|
# CPP_Default_XXX
|
|||
|
|
|||
|
- **功能描述:** XXX=参数名字
|
|||
|
- **使用位置:** UPARAM
|
|||
|
- **引擎模块:** Blueprint
|
|||
|
- **元数据类型:** string="abc"
|
|||
|
- **常用程度:** ★★★★★
|
|||
|
|
|||
|
在UFUNCTION的meta上保存参数的默认值。
|
|||
|
|
|||
|
## 测试代码:
|
|||
|
|
|||
|
```cpp
|
|||
|
//(CPP_Default_intValue = 123, CPP_Default_intValue2 = 456, ModuleRelativePath = Function/Param/MyFunction_TestParam.h)
|
|||
|
UFUNCTION(BlueprintCallable)
|
|||
|
FString MyFuncTestParam_DefaultInt2(int intValue=123,int intValue2=456);
|
|||
|
```
|
|||
|
|
|||
|
在Meta里也可以直接写属性的默认值,如Duration。
|
|||
|
|
|||
|
```cpp
|
|||
|
UFUNCTION(BlueprintCallable, Category="Utilities|FlowControl", meta=(Latent, WorldContext="WorldContextObject", LatentInfo="LatentInfo", Duration="0.2", Keywords="sleep"))
|
|||
|
static ENGINE_API void MyDelay(const UObject* WorldContextObject, float Duration, struct FLatentActionInfo LatentInfo );
|
|||
|
```
|
|||
|
|
|||
|
## 原理代码:
|
|||
|
|
|||
|
在UEdGraphSchema_K2::FindFunctionParameterDefaultValue里会尝试找该参数名称对应的Meta。如果找不到则会继续找CPP_Default_ParamName这个名称。然后设置到Pin->AutogeneratedDefaultValue
|
|||
|
|
|||
|
```cpp
|
|||
|
bool UK2Node_CallFunction::CreatePinsForFunctionCall(const UFunction* Function)
|
|||
|
{
|
|||
|
FString ParamValue;
|
|||
|
if (K2Schema->FindFunctionParameterDefaultValue(Function, Param, ParamValue))
|
|||
|
{
|
|||
|
K2Schema->SetPinAutogeneratedDefaultValue(Pin, ParamValue);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
K2Schema->SetPinAutogeneratedDefaultValueBasedOnType(Pin);
|
|||
|
}
|
|||
|
}
|
|||
|
```
|