.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
AdvancedDisplay
AllowPrivateAccess
BlueprintAutocast
BlueprintPrivate
BlueprintProtected
BlueprintThreadSafe
CallableWithoutWorldContext
CommutativeAssociativeBinaryOperator
CompactNodeTitle
DefaultToSelf
DontUseGenericSpawnObject
Exec
ExposeOnSpawn
ExposedAsyncProxy
ForceAsFunction
HasDedicatedAsyncNode
HiddenNode
HideThen
IgnoreTypePromotion
Keywords
KismetHideOverrides
Latent
NativeMakeFunc
NotInputConfigurable
ObjectSetType
Param
ArrayParm
ArrayTypeDependentParams
AutoCreateRefTerm
AutoCreateRefTerm.md
Untitled.png
CustomStructureParam
DeterminesOutputType
HideSpawnParms
MapParam
DynamicOutputParam.md
ProhibitedInterfaces
RestrictedToClasses
ReturnDisplayName
SetParam
ShowWorldContextPin
UnsafeDuringActorConstruction
WorldContext
BlueprintGetter.md
BlueprintInternalUseOnly.md
BlueprintInternalUseOnlyHierarchical.md
BlueprintSetter.md
BlueprintType.md
CPP_Default_XXX.md
CallInEditor.md
CannotImplementInterfaceInBlueprint.md
DisplayName.md
GetByRef.md
HideFunctions.md
IsBlueprintBase.md
IsConversionRoot.md
NativeBreakFunc.md
NativeConst.md
NotBlueprintThreadSafe.md
SparseClassDataTypes.md
Variadic.md
Component
Config
Container
Debug
DetailsPanel
Development
Enum
GAS
Material
Niagara
Numeric
Object
Path
Pin
RigVM
Scene
Script
Sequencer
Serialization
SparseDataType
String
Struct
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
4.6 KiB
4.6 KiB
AutoCreateRefTerm
- 功能描述: 指定函数的多个输入引用参数在没有连接的时候自动为其创建默认值
- 使用位置: UFUNCTION
- 引擎模块: Blueprint
- 元数据类型: strings="a,b,c"
- 常用程度: ★★★★★
指定函数的多个输入引用参数在没有连接的时候自动为其创建默认值。
要注意“输入”+“引用”,这两个前提项。
当有些情况你想把函数的参数采用引用来传递,但是又不想每次都得必须连接一个变量,想在不连接的时候提供一个内联编辑的默认值,因此蓝图系统就提供了这么一个便利功能。
测试代码:
UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Location,Value"))
static bool MyFunc_HasAutoCreateRefTerm(const FVector& Location, const int32& Value) { return false; }
UFUNCTION(BlueprintCallable)
static bool MyFunc_NoAutoCreateRefTerm(const FVector& Location, const int32& Value) { return false; }
UFUNCTION(BlueprintCallable)
static bool MyFunc_NoRef(FVector Location, int32 Value) { return false; }
蓝图效果:
可以见到MyFunc_NoAutoCreateRefTerm的函数会产生编译的报错,因为是引用参数但是却没有连接,导致引用缺少实参。
原理代码:
void UEdGraphSchema_K2::GetAutoEmitTermParameters(const UFunction* Function, TArray<FString>& AutoEmitParameterNames)
{
AutoEmitParameterNames.Reset();
const FString& MetaData = Function->GetMetaData(FBlueprintMetadata::MD_AutoCreateRefTerm);
if (!MetaData.IsEmpty())
{
MetaData.ParseIntoArray(AutoEmitParameterNames, TEXT(","), true);
for (int32 NameIndex = 0; NameIndex < AutoEmitParameterNames.Num();)
{
FString& ParameterName = AutoEmitParameterNames[NameIndex];
ParameterName.TrimStartAndEndInline();
if (ParameterName.IsEmpty())
{
AutoEmitParameterNames.RemoveAtSwap(NameIndex);
}
else
{
++NameIndex;
}
}
}
// Allow any params that are blueprint defined to be autocreated:
if (!FBlueprintEditorUtils::IsNativeSignature(Function))
{
for ( TFieldIterator<FProperty> ParamIter(Function, EFieldIterationFlags::Default);
ParamIter && (ParamIter->PropertyFlags & CPF_Parm);
++ParamIter)
{
FProperty* Param = *ParamIter;
if(Param->HasAnyPropertyFlags(CPF_ReferenceParm))
{
AutoEmitParameterNames.Add(Param->GetName());
}
}
}
}
还有在
void UK2Node_CallFunction::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
{
if ( Function )
{
TArray<FString> AutoCreateRefTermPinNames;
CompilerContext.GetSchema()->GetAutoEmitTermParameters(Function, AutoCreateRefTermPinNames);
const bool bHasAutoCreateRefTerms = AutoCreateRefTermPinNames.Num() != 0;
for (UEdGraphPin* Pin : Pins)
{
const bool bIsRefInputParam = Pin && Pin->PinType.bIsReference && (Pin->Direction == EGPD_Input) && !CompilerContext.GetSchema()->IsMetaPin(*Pin);
if (!bIsRefInputParam)
{
continue;
}
const bool bHasConnections = Pin->LinkedTo.Num() > 0;
const bool bCreateDefaultValRefTerm = bHasAutoCreateRefTerms &&
!bHasConnections && AutoCreateRefTermPinNames.Contains(Pin->PinName.ToString());
if (bCreateDefaultValRefTerm)
{
const bool bHasDefaultValue = !Pin->DefaultValue.IsEmpty() || Pin->DefaultObject || !Pin->DefaultTextValue.IsEmpty();
// copy defaults as default values can be reset when the pin is connected
const FString DefaultValue = Pin->DefaultValue;
UObject* DefaultObject = Pin->DefaultObject;
const FText DefaultTextValue = Pin->DefaultTextValue;
bool bMatchesDefaults = Pin->DoesDefaultValueMatchAutogenerated();
UEdGraphPin* ValuePin = InnerHandleAutoCreateRef(this, Pin, CompilerContext, SourceGraph, bHasDefaultValue);
if ( ValuePin )
{
if (bMatchesDefaults)
{
// Use the latest code to set default value
Schema->SetPinAutogeneratedDefaultValueBasedOnType(ValuePin);
}
else
{
ValuePin->DefaultValue = DefaultValue;
ValuePin->DefaultObject = DefaultObject;
ValuePin->DefaultTextValue = DefaultTextValue;
}
}
}
// since EX_Self does not produce an addressable (referenceable) FProperty, we need to shim
// in a "auto-ref" term in its place (this emulates how UHT generates a local value for
// native functions; hence the IsNative() check)
else if (bHasConnections && Pin->LinkedTo[0]->PinType.PinSubCategory == UEdGraphSchema_K2::PSC_Self && Pin->PinType.bIsConst && !Function->IsNative())
{
InnerHandleAutoCreateRef(this, Pin, CompilerContext, SourceGraph, /*bForceAssignment =*/true);
}
}
}
}