UE蓝图 入口(FunctionEntry)节点和源码

系列文章目录

UE蓝图 Get节点和源码
UE蓝图 Set节点和源码
UE蓝图 Cast节点和源码
UE蓝图 分支(Branch)节点和源码
UE蓝图 入口(FunctionEntry)节点和源码


文章目录

  • 系列文章目录
  • 一、FunctionEntry节点功能
  • 二、入口节点用法
      • 1. 创建函数
      • 2. 命名函数
      • 3. 定义参数
      • 4. 编写函数逻辑
      • 5. 连接节点
      • 6. 返回值
      • 7. 调用函数
  • 三、使用场景
      • 1. 游戏逻辑处理
      • 2. 用户界面交互
      • 3. 系统功能实现
      • 4. 物理和碰撞处理
      • 5. 人工智能和机器学习
      • 6. 网络和多人游戏
      • 7. 工具和功能扩展
  • 四、实现过程
  • 五、相关源码


一、FunctionEntry节点功能

在UE(Unreal Engine)蓝图中,K2Node_FunctionEntry 是UE蓝图中函数或宏的入口节点,通常被称为“函数入口节点”或“FunctionEntry”。这个节点是一个事件节点,它标志着函数或宏的开始执行。当这个函数或宏被调用时,FunctionEntry 节点会被激活,从而触发函数或宏内部的逻辑执行。
在这里插入图片描述

K2Node_FunctionEntry 节点通常位于函数或宏的开始位置,并且只有一个指向函数或宏内部节点的白色箭头。当函数或宏被激活时,FunctionEntry 节点会按照连接流的顺序执行后续的节点。这意味着在函数或宏被调用后,首先会执行FunctionEntry 节点,然后按照连接关系依次执行后续的节点,直到函数或宏执行完毕。

二、入口节点用法

UE蓝图中的FunctionEntry节点是函数的起点,用于定义函数的行为和逻辑。以下是关于FunctionEntry节点用法的详细解释:
在这里插入图片描述

1. 创建函数

首先,在蓝图中创建一个新函数。这通常通过在蓝图编辑器中右键单击并选择“添加新函数”来完成。

2. 命名函数

为新函数提供一个有意义的名称,这将帮助你在后续的编程过程中更容易地识别和管理函数。

3. 定义参数

FunctionEntry节点中,你可以定义函数的输入和输出参数。输入参数是传递给函数的数据,而输出参数是函数处理完数据后返回的结果。

4. 编写函数逻辑

FunctionEntry节点下方,你可以开始添加执行函数所需的逻辑节点。这些节点可以是变量设置、条件判断、循环执行等。

5. 连接节点

使用白色箭头将节点连接起来,以定义数据流的顺序。例如,你可能将一个变量的值传递给一个运算节点,然后将运算结果传递给另一个节点。

6. 返回值

如果函数有输出参数或返回值,确保在函数的最后部分正确设置这些值。这样,当函数执行完毕时,调用者可以接收这些值。

7. 调用函数

要在蓝图的其他部分调用这个函数,你需要使用Call Function节点。将Call Function节点的输出连接到FunctionEntry节点,这样当Call Function节点被激活时,它将触发函数的执行。

三、使用场景

一些常见的FunctionEntry节点应用场景:

1. 游戏逻辑处理

在游戏开发中,FunctionEntry节点常被用于处理游戏逻辑,如玩家控制、敌人行为、碰撞检测等。通过将游戏逻辑分解为不同的函数,可以使代码更加清晰,便于调试和维护。

2. 用户界面交互

在创建用户界面(UI)时,FunctionEntry节点可以用于处理用户输入和界面交互。例如,当玩家点击一个按钮时,可以调用一个函数来处理相应的点击事件,如打开一个新的菜单或执行某个动作。

3. 系统功能实现

FunctionEntry节点也可以用于实现游戏中的各种系统功能,如保存和加载游戏进度、处理游戏设置、管理资源等。通过将这些功能分解为独立的函数,可以提高代码的可重用性和可维护性。

4. 物理和碰撞处理

在物理模拟和碰撞检测方面,FunctionEntry节点可以用于实现物理引擎的各种功能,如刚体运动、碰撞响应等。通过将物理模拟的逻辑分解为不同的函数,可以提高代码的可读性和性能。

5. 人工智能和机器学习

在涉及人工智能(AI)和机器学习(ML)的应用中,FunctionEntry节点可以用于实现复杂的算法和逻辑。例如,在路径规划、决策树、神经网络等方面,通过将算法分解为不同的函数,可以更容易地实现和调试这些高级功能。

6. 网络和多人游戏

在网络游戏和多人在线游戏中,FunctionEntry节点可以用于处理网络通信、玩家同步、状态更新等逻辑。通过将网络相关的逻辑分解为独立的函数,可以简化代码结构,提高游戏的稳定性和可扩展性。

7. 工具和功能扩展

此外,FunctionEntry节点还可以用于创建自定义的工具和功能扩展。例如,开发者可以创建自己的函数来处理特定的任务,如资源生成、场景编辑、调试工具等。

四、实现过程

  • 创建输入输出引脚
void UK2Node_FunctionEntry::AllocateDefaultPins()
{// Update our default values before copying them into pinsUpdateLoadedDefaultValues();CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);// Find any pins inherited from parentif (UFunction* Function = FunctionReference.ResolveMember<UFunction>(GetBlueprintClassFromNode())){CreatePinsForFunctionEntryExit(Function, /*bIsFunctionEntry=*/ true);}Super::AllocateDefaultPins();if (FFunctionEntryHelper::RequireWorldContextParameter(this) && ensure(!FindPin(FFunctionEntryHelper::GetWorldContextPinName()))){UEdGraphPin* WorldContextPin = CreatePin(EGPD_Output,UEdGraphSchema_K2::PC_Object,UObject::StaticClass(),FFunctionEntryHelper::GetWorldContextPinName());WorldContextPin->bHidden = true;}
}
  • 调用FKCHandler_FunctionEntry.RegisterNets注册Net

  • 调用Compile编译创建Statement

UK2Node_FunctionEntry* EntryNode = CastChecked<UK2Node_FunctionEntry>(Node);
if (EntryNode->FunctionReference.GetMemberName() == UEdGraphSchema_K2::FN_ExecuteUbergraphBase)
{UEdGraphPin* EntryPointPin = Node->FindPin(UEdGraphSchema_K2::PN_EntryPoint);FBPTerminal** pTerm = Context.NetMap.Find(EntryPointPin);if ((EntryPointPin != nullptr) && (pTerm != nullptr)){FBlueprintCompiledStatement& ComputedGotoStatement = Context.AppendStatementForNode(Node);ComputedGotoStatement.Type = KCST_ComputedGoto;ComputedGotoStatement.LHS = *pTerm;}
}
else
{// Generate the output impulse from this nodeGenerateSimpleThenGoto(Context, *Node);
}

五、相关源码

源码文件:
K2Node_FunctionEntry.h
K2Node_FunctionEntry.cpp
相关类:
FKCHandler_FunctionEntry
K2Node_FunctionEntry


class FKCHandler_FunctionEntry : public FNodeHandlingFunctor
{
public:FKCHandler_FunctionEntry(FKismetCompilerContext& InCompilerContext): FNodeHandlingFunctor(InCompilerContext){}void RegisterFunctionInput(FKismetFunctionContext& Context, UEdGraphPin* Net, UFunction* Function){// This net is a parameter into the functionFBPTerminal* Term = new FBPTerminal();Context.Parameters.Add(Term);Term->CopyFromPin(Net, Net->PinName);// Flag pass by reference parameters specially//@TODO: Still doesn't handle/allow users to declare new pass by reference, this only helps inherited functionsif( Function ){if (FProperty* ParentProperty = FindFProperty<FProperty>(Function, Net->PinName)){if (ParentProperty->HasAnyPropertyFlags(CPF_ReferenceParm)){Term->bPassedByReference = true;}}}Context.NetMap.Add(Net, Term);}virtual void RegisterNets(FKismetFunctionContext& Context, UEdGraphNode* Node) override{UK2Node_FunctionEntry* EntryNode = CastChecked<UK2Node_FunctionEntry>(Node);UFunction* Function = EntryNode->FunctionReference.ResolveMember<UFunction>(EntryNode->GetBlueprintClassFromNode());// if this function has a predefined signature (like for inherited/overridden // functions), then we want to make sure to account for the output // parameters - this is normally handled by the FunctionResult node, but // we're not guaranteed that one is connected to the entry node if (Function && Function->HasAnyFunctionFlags(FUNC_HasOutParms)){const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();for (TFieldIterator<FProperty> ParamIt(Function, EFieldIteratorFlags::ExcludeSuper); ParamIt; ++ParamIt){FProperty* ParamProperty = *ParamIt;// mirrored from UK2Node_FunctionResult::CreatePinsForFunctionEntryExit()const bool bIsFunctionInput = !ParamProperty->HasAnyPropertyFlags(CPF_OutParm) || ParamProperty->HasAnyPropertyFlags(CPF_ReferenceParm);if (bIsFunctionInput){// continue;}FEdGraphPinType ParamType;if (K2Schema->ConvertPropertyToPinType(ParamProperty, ParamType)){FString ParamName = ParamProperty->GetName();bool bTermExists = false;// check to see if this terminal already exists (most // likely added by a FunctionResult node) - if so, then // we don't need to add it ourselvesfor (const FBPTerminal& ResultTerm : Context.Results){if (ResultTerm.Name == ParamName && ResultTerm.Type == ParamType){bTermExists = true;break;}}if (!bTermExists){// create a terminal that represents a output param // for this function; if there is a FunctionResult // node wired into our function graph, know that it// will first check to see if this already exists // for it to use (rather than creating one of its own)FBPTerminal* ResultTerm = new FBPTerminal();Context.Results.Add(ResultTerm);ResultTerm->Name = ParamName;ResultTerm->Type = ParamType;ResultTerm->bPassedByReference = ParamType.bIsReference;ResultTerm->SetContextTypeStruct(ParamType.PinCategory == UEdGraphSchema_K2::PC_Struct && Cast<UScriptStruct>(ParamType.PinSubCategoryObject.Get()));}}}}for (UEdGraphPin* Pin : Node->Pins){if (Pin->ParentPin == nullptr && !CompilerContext.GetSchema()->IsMetaPin(*Pin)){UEdGraphPin* Net = FEdGraphUtilities::GetNetFromPin(Pin);if (Context.NetMap.Find(Net) == nullptr){// New net, resolve the term that will be used to construct itFBPTerminal* Term = nullptr;check(Net->Direction == EGPD_Output);RegisterFunctionInput(Context, Pin, Function);}}}}virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override{UK2Node_FunctionEntry* EntryNode = CastChecked<UK2Node_FunctionEntry>(Node);//check(EntryNode->SignatureName != NAME_None);if (EntryNode->FunctionReference.GetMemberName() == UEdGraphSchema_K2::FN_ExecuteUbergraphBase){UEdGraphPin* EntryPointPin = Node->FindPin(UEdGraphSchema_K2::PN_EntryPoint);FBPTerminal** pTerm = Context.NetMap.Find(EntryPointPin);if ((EntryPointPin != nullptr) && (pTerm != nullptr)){FBlueprintCompiledStatement& ComputedGotoStatement = Context.AppendStatementForNode(Node);ComputedGotoStatement.Type = KCST_ComputedGoto;ComputedGotoStatement.LHS = *pTerm;}else{CompilerContext.MessageLog.Error(*LOCTEXT("NoEntryPointPin_Error", "Expected a pin named EntryPoint on @@").ToString(), Node);}}else{// Generate the output impulse from this nodeGenerateSimpleThenGoto(Context, *Node);}}virtual bool RequiresRegisterNetsBeforeScheduling() const override{return true;}
};struct FFunctionEntryHelper
{static const FName& GetWorldContextPinName(){static const FName WorldContextPinName(TEXT("__WorldContext"));return WorldContextPinName;}static bool RequireWorldContextParameter(const UK2Node_FunctionEntry* Node){const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();return K2Schema->IsStaticFunctionGraph(Node->GetGraph());}
};UK2Node_FunctionEntry::UK2Node_FunctionEntry(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)
{// Enforce const-correctness by defaultbEnforceConstCorrectness = true;bUpdatedDefaultValuesOnLoad = false;bCanRenameNode = bIsEditable;
}void UK2Node_FunctionEntry::PreSave(const class ITargetPlatform* TargetPlatform)
{Super::PreSave(TargetPlatform);const UBlueprint* Blueprint = HasValidBlueprint() ? GetBlueprint() : nullptr;if (Blueprint && LocalVariables.Num() > 0){// Forcibly fixup defaults before we saveUpdateLoadedDefaultValues(true);}
}void UK2Node_FunctionEntry::PostLoad()
{Super::PostLoad();if (GIsEditor){// In the editor, we need to handle processing function default values at load time so they get picked up properly by the cooker// This normally won't do anything because it gets called during the duplicate save during BP compilation, but if compilation gets skipped we need to make sure they get updatedUpdateLoadedDefaultValues();}
}void UK2Node_FunctionEntry::Serialize(FArchive& Ar)
{Super::Serialize(Ar);Ar.UsingCustomVersion(FBlueprintsObjectVersion::GUID);if (Ar.IsSaving()){		if (Ar.IsObjectReferenceCollector() || Ar.Tell() < 0){// If this is explicitly a reference collector, or it's a save with no backing archive, then we want to use the function variable cache if it exists// It's not safe to regenerate the cache at this point as we could be in GIsSavingif (FunctionVariableCache.IsValid() && FunctionVariableCache->IsValid()){UStruct* Struct = const_cast<UStruct*>(FunctionVariableCache->GetStruct());Struct->SerializeBin(Ar, FunctionVariableCache->GetStructMemory());// Copy back into defaults as they may have changedUpdateDefaultsFromVariableStruct(FunctionVariableCache->GetStruct(), FunctionVariableCache->GetStructMemory());}}}else if (Ar.IsLoading()){if (Ar.CustomVer(FFrameworkObjectVersion::GUID) < FFrameworkObjectVersion::LocalVariablesBlueprintVisible){for (FBPVariableDescription& LocalVariable : LocalVariables){LocalVariable.PropertyFlags |= CPF_BlueprintVisible;}}if (Ar.UE4Ver() < VER_UE4_BLUEPRINT_ENFORCE_CONST_IN_FUNCTION_OVERRIDES|| ((Ar.CustomVer(FFrameworkObjectVersion::GUID) < FFrameworkObjectVersion::EnforceConstInAnimBlueprintFunctionGraphs) && GetBlueprint()->IsA<UAnimBlueprint>())){// Allow legacy implementations to violate const-correctnessbEnforceConstCorrectness = false;}if (Ar.CustomVer(FBlueprintsObjectVersion::GUID) < FBlueprintsObjectVersion::CleanBlueprintFunctionFlags){// Flags we explicitly use ExtraFlags for (at the time this fix was made)://     FUNC_Public, FUNC_Protected, FUNC_Private, //     FUNC_Static, FUNC_Const,//     FUNC_BlueprintPure, FUNC_BlueprintCallable, FUNC_BlueprintEvent, FUNC_BlueprintAuthorityOnly,//     FUNC_Net, FUNC_NetMulticast, FUNC_NetServer, FUNC_NetClient, FUNC_NetReliable// // FUNC_Exec, FUNC_Event, & FUNC_BlueprintCosmetic are all inherited // in FKismetCompilerContext::PrecompileFunction()static const uint32 InvalidExtraFlagsMask = FUNC_Final | FUNC_RequiredAPI | FUNC_BlueprintCosmetic |FUNC_NetRequest | FUNC_Exec | FUNC_Native | FUNC_Event | FUNC_NetResponse | FUNC_MulticastDelegate |FUNC_Delegate | FUNC_HasOutParms | FUNC_HasDefaults | FUNC_DLLImport | FUNC_NetValidate;ExtraFlags &= ~InvalidExtraFlagsMask;}if (Ar.CustomVer(FFrameworkObjectVersion::GUID) < FFrameworkObjectVersion::ChangeAssetPinsToString){const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();// Prior to this version, changing the type of a local variable would lead to corrupt default value stringsfor (FBPVariableDescription& LocalVar : LocalVariables){FString UseDefaultValue;UObject* UseDefaultObject = nullptr;FText UseDefaultText;if (!LocalVar.DefaultValue.IsEmpty()){K2Schema->GetPinDefaultValuesFromString(LocalVar.VarType, this, LocalVar.DefaultValue, UseDefaultValue, UseDefaultObject, UseDefaultText);FString ErrorMessage;if (!K2Schema->DefaultValueSimpleValidation(LocalVar.VarType, LocalVar.VarName, UseDefaultValue, UseDefaultObject, UseDefaultText, &ErrorMessage)){const UBlueprint* Blueprint = GetBlueprint();UE_LOG(LogBlueprint, Log, TEXT("Clearing invalid default value for local variable %s on blueprint %s: %s"), *LocalVar.VarName.ToString(), Blueprint ? *Blueprint->GetName() : TEXT("Unknown"), *ErrorMessage);LocalVar.DefaultValue.Reset();}}}}}
}FText UK2Node_FunctionEntry::GetNodeTitle(ENodeTitleType::Type TitleType) const
{UEdGraph* Graph = GetGraph();FGraphDisplayInfo DisplayInfo;Graph->GetSchema()->GetGraphDisplayInformation(*Graph, DisplayInfo);return DisplayInfo.DisplayName;
}void UK2Node_FunctionEntry::OnRenameNode(const FString& NewName)
{// Note: RenameGraph() will handle the rename operation for this node as well.FBlueprintEditorUtils::RenameGraph(GetGraph(), NewName);
}TSharedPtr<class INameValidatorInterface> UK2Node_FunctionEntry::MakeNameValidator() const
{if (CustomGeneratedFunctionName.IsNone()){FText TextName = GetNodeTitle(ENodeTitleType::Type::EditableTitle);return MakeShareable(new FKismetNameValidator(GetBlueprint(), *TextName.ToString()));}else{return MakeShareable(new FKismetNameValidator(GetBlueprint(), CustomGeneratedFunctionName));}
}bool UK2Node_FunctionEntry::GetCanRenameNode() const
{UEdGraph* const Graph = GetGraph();return (Graph && (Graph->bAllowDeletion || Graph->bAllowRenaming) && (bCanRenameNode || bIsEditable));
}void UK2Node_FunctionEntry::AllocateDefaultPins()
{// Update our default values before copying them into pinsUpdateLoadedDefaultValues();CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);// Find any pins inherited from parentif (UFunction* Function = FunctionReference.ResolveMember<UFunction>(GetBlueprintClassFromNode())){CreatePinsForFunctionEntryExit(Function, /*bIsFunctionEntry=*/ true);}Super::AllocateDefaultPins();if (FFunctionEntryHelper::RequireWorldContextParameter(this) && ensure(!FindPin(FFunctionEntryHelper::GetWorldContextPinName()))){UEdGraphPin* WorldContextPin = CreatePin(EGPD_Output,UEdGraphSchema_K2::PC_Object,UObject::StaticClass(),FFunctionEntryHelper::GetWorldContextPinName());WorldContextPin->bHidden = true;}
}UEdGraphPin* UK2Node_FunctionEntry::GetAutoWorldContextPin() const
{return FindPin(FFunctionEntryHelper::GetWorldContextPinName());
}void UK2Node_FunctionEntry::RemoveOutputPin(UEdGraphPin* PinToRemove)
{UK2Node_FunctionEntry* OwningSeq = Cast<UK2Node_FunctionEntry>( PinToRemove->GetOwningNode() );if (OwningSeq){PinToRemove->MarkPendingKill();OwningSeq->Pins.Remove(PinToRemove);}
}bool UK2Node_FunctionEntry::CanCreateUserDefinedPin(const FEdGraphPinType& InPinType, EEdGraphPinDirection InDesiredDirection, FText& OutErrorMessage)
{bool bResult = Super::CanCreateUserDefinedPin(InPinType, InDesiredDirection, OutErrorMessage);if (bResult){if(InDesiredDirection == EGPD_Input){OutErrorMessage = LOCTEXT("AddInputPinError", "Cannot add input pins to function entry node!");bResult = false;}}return bResult;
}UEdGraphPin* UK2Node_FunctionEntry::CreatePinFromUserDefinition(const TSharedPtr<FUserPinInfo> NewPinInfo)
{// Make sure that if this is an exec node we are allowed one.const UEdGraphSchema_K2* Schema = GetDefault<UEdGraphSchema_K2>();if (NewPinInfo->PinType.PinCategory == UEdGraphSchema_K2::PC_Exec && !CanModifyExecutionWires()){return nullptr;}UEdGraphPin* NewPin = CreatePin(EGPD_Output, NewPinInfo->PinType, NewPinInfo->PinName);Schema->SetPinAutogeneratedDefaultValue(NewPin, NewPinInfo->PinDefaultValue);return NewPin;
}TSharedPtr<FStructOnScope> UK2Node_FunctionEntry::GetFunctionVariableCache(bool bForceRefresh)
{if (bForceRefresh && FunctionVariableCache.IsValid()){// On force refresh, delete old one if it existsFunctionVariableCache.Reset();}if (!FunctionVariableCache.IsValid() || !FunctionVariableCache->IsValid()){if (UFunction* const Function = FindSignatureFunction()){if (LocalVariables.Num() > 0){FunctionVariableCache = MakeShared<FStructOnScope>(Function);FunctionVariableCache->SetPackage(GetOutermost());RefreshFunctionVariableCache();}}}return FunctionVariableCache;
}bool UK2Node_FunctionEntry::RefreshFunctionVariableCache()
{GetFunctionVariableCache(false);if (FunctionVariableCache.IsValid()){// Update the cache if it was createdreturn UpdateVariableStructFromDefaults(FunctionVariableCache->GetStruct(), FunctionVariableCache->GetStructMemory());}return false;
}bool UK2Node_FunctionEntry::UpdateLoadedDefaultValues(bool bForceRefresh)
{// If we don't have a cache or it's force refresh, create oneif (!bUpdatedDefaultValuesOnLoad || bForceRefresh){GetFunctionVariableCache(bForceRefresh);bUpdatedDefaultValuesOnLoad = true;if (FunctionVariableCache.IsValid()){// Now copy back into the default value stringsreturn UpdateDefaultsFromVariableStruct(FunctionVariableCache->GetStruct(), FunctionVariableCache->GetStructMemory());}else{// No variable cache createdreturn true;}}return false;
}void UK2Node_FunctionEntry::ClearCachedBlueprintData(UBlueprint* Blueprint)
{FunctionVariableCache.Reset();
}bool UK2Node_FunctionEntry::UpdateVariableStructFromDefaults(const UStruct* VariableStruct, uint8* VariableStructData)
{const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();if (!VariableStruct || !VariableStructData){return false;}for (FBPVariableDescription& LocalVariable : LocalVariables){if (!LocalVariable.DefaultValue.IsEmpty()){FProperty* PinProperty = VariableStruct->FindPropertyByName(LocalVariable.VarName);if (PinProperty && (!PinProperty->HasAnyPropertyFlags(CPF_OutParm) || PinProperty->HasAnyPropertyFlags(CPF_ReferenceParm))){FEdGraphPinType PinType;K2Schema->ConvertPropertyToPinType(PinProperty, /*out*/ PinType);if (PinType != LocalVariable.VarType){//UE_LOG(LogBlueprint, Log, TEXT("Pin type for local variable %s does not match type on struct %s during UpdateVariableStructFromDefaults, ignoring old default"), *LocalVariable.VarName.ToString(), *VariableStruct->GetName());}else{FBlueprintEditorUtils::PropertyValueFromString(PinProperty, LocalVariable.DefaultValue, VariableStructData, this);}}else{//UE_LOG(LogBlueprint, Log, TEXT("Could not find local variable property %s on struct %s during UpdateVariableStructFromDefaults"), *LocalVariable.VarName.ToString(), *VariableStruct->GetName());}}}return true;
}bool UK2Node_FunctionEntry::UpdateDefaultsFromVariableStruct(const UStruct* VariableStruct, uint8* VariableStructData)
{const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();if (!VariableStruct || !VariableStructData){return false;}for (FBPVariableDescription& LocalVariable : LocalVariables){if (!LocalVariable.DefaultValue.IsEmpty()){// We don't want to write out fields that were empty before, as they were guaranteed to not have actual real dataFProperty* PinProperty = VariableStruct->FindPropertyByName(LocalVariable.VarName);if (PinProperty && (!PinProperty->HasAnyPropertyFlags(CPF_OutParm) || PinProperty->HasAnyPropertyFlags(CPF_ReferenceParm))){FEdGraphPinType PinType;K2Schema->ConvertPropertyToPinType(PinProperty, /*out*/ PinType);if (PinType != LocalVariable.VarType){//UE_LOG(LogBlueprint, Log, TEXT("Pin type for local variable %s does not match type on struct %s during UpdateDefaultsFromVariableStruct, ignoring old default"), *LocalVariable.VarName.ToString(), *VariableStruct->GetName());}else{FString NewValue;FBlueprintEditorUtils::PropertyValueToString(PinProperty, VariableStructData, NewValue, this);if (NewValue != LocalVariable.DefaultValue){LocalVariable.DefaultValue = NewValue;}}}else{//UE_LOG(LogBlueprint, Log, TEXT("Could not find local variable property %s on struct %s during UpdateDefaultsFromVariableStruct"), *LocalVariable.VarName.ToString(), *VariableStruct->GetName());}}}return true;
}FNodeHandlingFunctor* UK2Node_FunctionEntry::CreateNodeHandler(FKismetCompilerContext& CompilerContext) const
{return new FKCHandler_FunctionEntry(CompilerContext);
}void UK2Node_FunctionEntry::GetRedirectPinNames(const UEdGraphPin& Pin, TArray<FString>& RedirectPinNames) const
{Super::GetRedirectPinNames(Pin, RedirectPinNames);if(RedirectPinNames.Num() > 0){const FString OldPinName = RedirectPinNames[0];// first add functionname.paramconst FName SignatureName = FunctionReference.GetMemberName();RedirectPinNames.Add(FString::Printf(TEXT("%s.%s"), *SignatureName.ToString(), *OldPinName));// if there is class, also add an option for class.functionname.paramif(UClass const* SignatureClass = FunctionReference.GetMemberParentClass()){RedirectPinNames.Add(FString::Printf(TEXT("%s.%s.%s"), *SignatureClass->GetName(), *SignatureName.ToString(), *OldPinName));}}
}bool UK2Node_FunctionEntry::HasDeprecatedReference() const
{// We only show deprecated for inherited functionsif (UFunction* const Function = FunctionReference.ResolveMember<UFunction>(GetBlueprintClassFromNode())){return Function->HasMetaData(FBlueprintMetadata::MD_DeprecatedFunction);}else{return MetaData.bIsDeprecated;}
}FEdGraphNodeDeprecationResponse UK2Node_FunctionEntry::GetDeprecationResponse(EEdGraphNodeDeprecationType DeprecationType) const
{FEdGraphNodeDeprecationResponse Response = Super::GetDeprecationResponse(DeprecationType);if (DeprecationType == EEdGraphNodeDeprecationType::NodeHasDeprecatedReference){// Only warn on non-editable (i.e. override) usage.if (!IsEditable()){UFunction* const Function = FunctionReference.ResolveMember<UFunction>(GetBlueprintClassFromNode());if (ensureMsgf(Function != nullptr, TEXT("This node should not be able to report having a deprecated reference if the override function cannot be resolved."))){FText FunctionName = FText::FromName(FunctionReference.GetMemberName());FText DetailedMessage = FText::FromString(Function->GetMetaData(FBlueprintMetadata::MD_DeprecationMessage));Response.MessageText = FBlueprintEditorUtils::GetDeprecatedMemberUsageNodeWarning(FunctionName, DetailedMessage);}}else{// Allow the function to be marked as deprecated in the class that defines it without warning, but use a note to visually indicate that the definition itself has been deprecated.Response.MessageType = EEdGraphNodeDeprecationMessageType::Note;Response.MessageText = LOCTEXT("DeprecatedFunctionMessage", "@@: This function has been marked as deprecated. It can be safely deleted if all references have been replaced or removed.");}}return Response;
}FText UK2Node_FunctionEntry::GetTooltipText() const
{if (UFunction* const Function = FindSignatureFunction()){return FText::FromString(UK2Node_CallFunction::GetDefaultTooltipForFunction(Function));}return Super::GetTooltipText();
}void UK2Node_FunctionEntry::FindDiffs(UEdGraphNode* OtherNode, struct FDiffResults& Results)
{Super::FindDiffs(OtherNode, Results);UK2Node_FunctionEntry* OtherFunction = Cast<UK2Node_FunctionEntry>(OtherNode);if (OtherFunction){if (ExtraFlags != OtherFunction->ExtraFlags){FDiffSingleResult Diff;Diff.Diff = EDiffType::NODE_PROPERTY;Diff.Node1 = this;Diff.Node2 = OtherNode;Diff.DisplayString = LOCTEXT("DIF_FunctionFlags", "Function flags have changed");Diff.DisplayColor = FLinearColor(0.25f, 0.71f, 0.85f);Results.Add(Diff);}if (!FKismetUserDeclaredFunctionMetadata::StaticStruct()->CompareScriptStruct(&MetaData, &OtherFunction->MetaData, 0)){FDiffSingleResult Diff;Diff.Diff = EDiffType::NODE_PROPERTY;Diff.Node1 = this;Diff.Node2 = OtherNode;Diff.DisplayString = LOCTEXT("DIF_FunctionMetadata", "Function metadata has changed");Diff.DisplayColor = FLinearColor(0.25f, 0.71f, 0.85f);Results.Add(Diff);}bool bLocalVarsDiffer = (LocalVariables.Num() != OtherFunction->LocalVariables.Num());for (int32 i = 0; i < LocalVariables.Num() && !bLocalVarsDiffer; i++){const FBPVariableDescription& ThisVar = LocalVariables[i];const FBPVariableDescription& OtherVar = OtherFunction->LocalVariables[i];// Can't do a raw compare, for local variable defaults we need to compare the structif (ThisVar.VarName != OtherVar.VarName|| ThisVar.VarType != OtherVar.VarType|| ThisVar.FriendlyName != OtherVar.FriendlyName|| !ThisVar.Category.EqualTo(OtherVar.Category)|| ThisVar.PropertyFlags != OtherVar.PropertyFlags|| ThisVar.RepNotifyFunc != OtherVar.RepNotifyFunc|| ThisVar.ReplicationCondition != OtherVar.ReplicationCondition){bLocalVarsDiffer = true;}}if (bLocalVarsDiffer){FDiffSingleResult Diff;Diff.Diff = EDiffType::NODE_PROPERTY;Diff.Node1 = this;Diff.Node2 = OtherNode;Diff.DisplayString = LOCTEXT("DIF_FunctionLocalVariables", "Function local variables have changed in structure");Diff.DisplayColor = FLinearColor(0.25f, 0.71f, 0.85f);Results.Add(Diff);}else{TSharedPtr<FStructOnScope> MyLocals = GetFunctionVariableCache();TSharedPtr<FStructOnScope> OtherLocals = OtherFunction->GetFunctionVariableCache();if (MyLocals.IsValid() && MyLocals->IsValid() && OtherLocals.IsValid() && OtherLocals->IsValid()){// Check for local var diffsFDiffSingleResult Diff;Diff.Diff = EDiffType::NODE_PROPERTY;Diff.Node1 = this;Diff.Node2 = OtherNode;Diff.ToolTip = LOCTEXT("DIF_FunctionLocalVariableDefaults", "Function local variable default values have changed");Diff.DisplayColor = FLinearColor(0.25f, 0.71f, 0.85f);DiffProperties(const_cast<UStruct*>(MyLocals->GetStruct()), const_cast<UStruct*>(OtherLocals->GetStruct()), MyLocals->GetStructMemory(), OtherLocals->GetStructMemory(), Results, Diff);}}}
}bool UK2Node_FunctionEntry::IsCompatibleWithGraph(const UEdGraph* InGraph) const
{if (CanCreateUnderSpecifiedSchema(InGraph->GetSchema())){if (InGraph->GetSchema()->GetGraphType(InGraph) == GT_Function){TArray<UK2Node_FunctionEntry*> Nodes;InGraph->GetNodesOfClass<UK2Node_FunctionEntry>(Nodes);return Nodes.Num() == 0;}}return false;
}void UK2Node_FunctionEntry::PostPasteNode()
{Super::PostPasteNode();// If a function entry is being pasted, it should be editable in it's new graphbIsEditable = true;// ensure there are UserDefinedPins for all pins except the 'then' pinfor (int32 PinIdx = 1; PinIdx < Pins.Num(); ++PinIdx){UEdGraphPin* Pin = Pins[PinIdx];if (Pin && !UserDefinedPinExists(Pin->GetFName())){UserDefinedPins.Add(MakeShared<FUserPinInfo>(*Pin));}}ReconstructNode();
}int32 UK2Node_FunctionEntry::GetFunctionFlags() const
{int32 ReturnFlags = 0;if (UFunction* const Function = FunctionReference.ResolveMember<UFunction>(GetBlueprintClassFromNode())){ReturnFlags = Function->FunctionFlags;}return ReturnFlags | ExtraFlags;
}void UK2Node_FunctionEntry::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
{Super::ExpandNode(CompilerContext, SourceGraph);const UEdGraphSchema_K2* Schema = CompilerContext.GetSchema();UEdGraphPin* OldStartExecPin = nullptr;if(Pins[0]->LinkedTo.Num()){OldStartExecPin = Pins[0]->LinkedTo[0];}UEdGraphPin* LastActiveOutputPin = Pins[0];// Only look for FunctionEntry nodes who were duplicated and have a source objectif ( UK2Node_FunctionEntry* OriginalNode = Cast<UK2Node_FunctionEntry>(CompilerContext.MessageLog.FindSourceObject(this)) ){check(OriginalNode->GetOuter());// Find the associated UFunctionUFunction* Function = FindUField<UFunction>(CompilerContext.Blueprint->SkeletonGeneratedClass, *OriginalNode->GetOuter()->GetName());// When regenerating on load, we may need to import text on certain properties to force load the assetsTSharedPtr<FStructOnScope> LocalVarData;if (Function && CompilerContext.Blueprint->bIsRegeneratingOnLoad){if (Function->GetStructureSize() > 0 || !ensure(Function->PropertyLink == nullptr)){LocalVarData = MakeShareable(new FStructOnScope(Function));}}for (TFieldIterator<FProperty> It(Function); It; ++It){if (const FProperty* Property = *It){const FStructProperty* PotentialUDSProperty = CastField<const FStructProperty>(Property);for (const FBPVariableDescription& LocalVar : LocalVariables){if (LocalVar.VarName == Property->GetFName() && !LocalVar.DefaultValue.IsEmpty()){// Add a variable set node for the local variable and hook it up immediately following the entry node or the last added local variableUK2Node_VariableSet* VariableSetNode = CompilerContext.SpawnIntermediateNode<UK2Node_VariableSet>(this, SourceGraph);VariableSetNode->SetFromProperty(Property, false, Property->GetOwnerClass());Schema->ConfigureVarNode(VariableSetNode, LocalVar.VarName, Function, CompilerContext.Blueprint);VariableSetNode->AllocateDefaultPins();if(UEdGraphPin* SetPin = VariableSetNode->FindPin(Property->GetFName())){if(LocalVar.VarType.IsArray()){TSharedPtr<FStructOnScope> StructData = MakeShareable(new FStructOnScope(Function));FBlueprintEditorUtils::PropertyValueFromString(Property, LocalVar.DefaultValue, StructData->GetStructMemory());// Create a Make Array node to setup the array's defaultsUK2Node_MakeArray* MakeArray = CompilerContext.SpawnIntermediateNode<UK2Node_MakeArray>(this, SourceGraph);MakeArray->AllocateDefaultPins();MakeArray->GetOutputPin()->MakeLinkTo(SetPin);MakeArray->PostReconstructNode();const FArrayProperty* ArrayProperty = CastField<FArrayProperty>(Property);check(ArrayProperty);FScriptArrayHelper_InContainer ArrayHelper(ArrayProperty, StructData->GetStructMemory());FScriptArrayHelper_InContainer DefaultArrayHelper(ArrayProperty, StructData->GetStructMemory());// Go through each element in the array to set the default valuefor( int32 ArrayIndex = 0 ; ArrayIndex < ArrayHelper.Num() ; ArrayIndex++ ){uint8* PropData = ArrayHelper.GetRawPtr(ArrayIndex);// Retrieve the element's default valueFString DefaultValue;FBlueprintEditorUtils::PropertyValueToString(ArrayProperty->Inner, PropData, DefaultValue);if(ArrayIndex > 0){MakeArray->AddInputPin();}// Add one to the index for the pin to set the default on to skip the output pinSchema->TrySetDefaultValue(*MakeArray->Pins[ArrayIndex + 1], DefaultValue);}}else if(LocalVar.VarType.IsSet() || LocalVar.VarType.IsMap()){UK2Node_MakeVariable* MakeVariableNode = CompilerContext.SpawnIntermediateNode<UK2Node_MakeVariable>(this, SourceGraph);MakeVariableNode->SetupVariable(LocalVar, SetPin, CompilerContext, Function, Property);}else{if (CompilerContext.Blueprint->bIsRegeneratingOnLoad){// When regenerating on load, we want to force load assets referenced by local variables.// This functionality is already handled when generating Terms in the Kismet Compiler for Arrays and Structs, so we do not have to worry about them.if (LocalVar.VarType.PinCategory == UEdGraphSchema_K2::PC_Object || LocalVar.VarType.PinCategory == UEdGraphSchema_K2::PC_Class || LocalVar.VarType.PinCategory == UEdGraphSchema_K2::PC_Interface){FBlueprintEditorUtils::PropertyValueFromString(Property, LocalVar.DefaultValue, LocalVarData->GetStructMemory());}}// Set the default valueSchema->TrySetDefaultValue(*SetPin, LocalVar.DefaultValue);}}LastActiveOutputPin->BreakAllPinLinks();LastActiveOutputPin->MakeLinkTo(VariableSetNode->Pins[0]);LastActiveOutputPin = VariableSetNode->Pins[1];}}}}// Finally, hook up the last node to the old node the function entry node was connected toif(OldStartExecPin){LastActiveOutputPin->MakeLinkTo(OldStartExecPin);}}
}void UK2Node_FunctionEntry::PostReconstructNode()
{Super::PostReconstructNode();
}void UK2Node_FunctionEntry::FixupPinStringDataReferences(FArchive* SavingArchive)
{Super::FixupPinStringDataReferences(SavingArchive);if (SavingArchive){UpdateUserDefinedPinDefaultValues();}
}bool UK2Node_FunctionEntry::ModifyUserDefinedPinDefaultValue(TSharedPtr<FUserPinInfo> PinInfo, const FString& NewDefaultValue)
{if (Super::ModifyUserDefinedPinDefaultValue(PinInfo, NewDefaultValue)){const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();K2Schema->HandleParameterDefaultValueChanged(this);RefreshFunctionVariableCache();return true;}return false;
}bool UK2Node_FunctionEntry::ShouldUseConstRefParams() const
{// Interface functions with no outputs will be implemented as events. As with native interface functions with no outputs, the entry// node is expected to use 'const Type&' for input parameters that are passed by reference. See UEditablePinBase::PostLoad() for details.if (const UEdGraph* OwningGraph = GetGraph()){const UBlueprint* OwningBlueprint = FBlueprintEditorUtils::FindBlueprintForGraph(OwningGraph);if (OwningBlueprint && OwningBlueprint->BlueprintType == BPTYPE_Interface){// Find paired result node and check for outputs.for (UEdGraphNode* Node : OwningGraph->Nodes){if (UK2Node_FunctionResult* ResultNode = Cast<UK2Node_FunctionResult>(Node)){// This might be called from the super's Serialize() method for older assets, so make sure the result node's pins have been loaded.if (ResultNode->HasAnyFlags(RF_NeedLoad)){GetLinker()->Preload(ResultNode);}return ResultNode->UserDefinedPins.Num() == 0;}}// No result node, so there are no outputs.return true;}}return false;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/261599.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

喜讯 | 重庆炼石入选重庆市科技局科技型企业

近日&#xff0c;重庆炼石网络技术有限公司&#xff08;以下简称“重庆炼石”&#xff09;经过严格审查&#xff0c;获得由重庆市科学技术局备案、重庆生产力促进中心&#xff08;重庆市科技型企业系统受托管理单位&#xff09;发证的《重庆市科技型企业备案证书》&#xff0c;…

国产洗地机品牌哪个好?热门品牌洗地机推荐

随着人们生活节奏的加快和生活压力的增加&#xff0c;“懒人好物”逐渐成为消费热点。在家庭清洁方面&#xff0c;吸尘器是最早被广泛接受的工具&#xff0c;但随着人们对便捷性和效率的需求增加&#xff0c;家用洗地机和扫地机器人等新型清洁工具开始受到欢迎。这些工具的出现…

入门OpenCV:图像阈值处理

图像阈值是一种简单、高效的图像分割方法&#xff0c;目的是将图像转换成二值图像。这个过程涉及比较像素值和阈值&#xff0c;根据比较结果来确定每个像素点的状态&#xff08;前景或背景&#xff09;。图像阈值在处理二维码、文本识别、物体跟踪等领域中非常有用。本博客旨在…

【图片公式识别】图片公式转Word与LaTeX文档:智能识别与转换

前言 嘿&#xff0c;大家好呀&#xff01;&#x1f44b; 谁都知道&#xff0c;写 Word 文档里的公式可不是一件简单的事情&#xff01;你辛辛苦苦在键盘上敲出的数学公式&#xff0c;结果随着 Word 版本的更新&#xff0c;竟然变成了一张图片&#xff01;&#x1f624; 这简直就…

微信小程序video 点击自动全屏播放

//因为这个地址可能是图片也可能是视频 点击 图片可以预览&#xff0c;点击视频可放大全屏自动播放。 代码如下 <view v-else :class{contentImg: x.picture.length0} style"margin-top: 10px;"v-for"(x1, y1) in x.picture" :key"y"><…

k8s(3)

目录 一.K8S的三种网络 flannel的三种模式: 在 node01 节点上操作&#xff1a; calico的 三种模式&#xff1a; flannel 与 calico 的区别&#xff1f; 二.CoreDNS 在所有 node 节点上操作&#xff1a; 在 master01 节点上操作&#xff1a; ​编辑 DNS 解析测试&#…

二叉树基础知识总结

目录 二叉树基础知识 概念 : 根节点的五个形态 : 特殊的二叉树 满二叉树 : 完全二叉树 : 二叉搜索树 : 平衡二叉搜索树 : 二叉树的性质 : 二叉树的存储结构 二叉树的顺序存储结构 二叉树的链式存储结构 二叉树的遍历方式 : 基础概念 前中后遍历 层序遍历 :…

新年新策略:2024数字化转型宝典,锁定趋势预测与关键部署策略

官.网地址&#xff1a;合合TextIn - 合合信息旗下OCR云服务产品 2024年是实现“十四五”规划目标任务的关键一年&#xff0c;以数字化驱动生产方式、生活方式和治理方式全面变革依旧是重中之重而作为数字化转型的助推器&#xff0c;信创同样是实现相关规划目标的一大抓手&…

OpenAI Sora引领AI跳舞视频新浪潮:字节跳动发布创新舞蹈视频生成框架

OpenAI的Sora已经引起广泛关注&#xff0c;预计今年AI跳舞视频将在抖音平台上大放异彩。下面将为您详细介绍一款字节跳动发布的AI视频动画框架。 技术定位&#xff1a;这款框架采用先进的diffusion技术&#xff0c;专注于生成人类舞蹈视频。它不仅能够实现人体动作和表情的迁移…

从零开始学习Netty - 学习笔记 - NIO基础 - 网络编程: Selector

4.网络编程 4.1.非阻塞 VS 阻塞 在网络编程中&#xff0c;**阻塞&#xff08;Blocking&#xff09;和非阻塞&#xff08;Non-blocking&#xff09;**是两种不同的编程模型&#xff0c;描述了程序在进行网络通信时的行为方式。 阻塞&#xff08;Blocking&#xff09;&#xff1…

电商平台商家结算

本文主要分析了目前电商清结算的流程以及自己对电商清结算的看法。 基本概念 先说下电商平台清结算的概念。简单说就是收的用户&#xff08;C端&#xff09;的付款&#xff0c;经过清分&#xff0c;再结算给对应商家。当然&#xff0c;这里排除那种资金不通过第三方&#xff0c…

django自定义后端过滤

​ DRF自带的过滤 第一个 DjangoFilterBackend 是需要安装三方库见[搜索&#xff1a;多字段筛选]两外两个是安装注册了rest_framework就有。 如上图&#xff0c;只要配置了三个箭头所指的方向&#xff0c;就能使用。 第一个单字段过滤 用户视图集中加上filterset_fields …

linux 系统的目录结构

为什么某些执行程序位于/bin、/sbin、/usr/bin或/usr/sbin目录下&#xff1f;例如&#xff0c;less命令位于/usr/bin目录下。为什么不是/bin、/sbin或/usr/sbin&#xff1f;这些目录之间有什么区别呢&#xff1f; 在这篇文章中&#xff0c;让我们主要讲述一下Linux文件系统结构…

IP协议及相关技术协议

一、IP基本认识 1. IP的作用 IP在TCP/IP模型中处于网络层&#xff0c;网络层的主要作用是实现主机与主机之间的通信&#xff0c;而IP的作用是在复杂的网络环境中将数据包发送给最终目的主机。 2. IP与MAC的关系 简单而言&#xff0c;MAC的作用是实现“直连”的两个设备之通信…

【深入理解设计模式】 工厂设计模式

工厂设计模式 工厂设计模式是一种创建型设计模式&#xff0c;它提供了一种在不指定具体类的情况下创建对象的接口。在工厂设计模式中&#xff0c;我们定义一个创建对象的接口&#xff0c;让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。 工厂设计模式的目…

Web安全之浅见

备注&#xff1a;这是我在2017年在自己的网站上写的文章&#xff0c;今天迁移过来。 昨天去参加了公司组织的一个关于网络安全的培训&#xff0c;了解了很多关于网络安全方面的知识&#xff0c;也才意识到网络安全是一项极其重要的领域。 本篇文章主要聊聊Web安全。不过我对于网…

区块链游戏解说:什么是 Planet IX

作者&#xff1a;lesleyfootprint.network 编译&#xff1a;cicifootprint.network 数据源&#xff1a;Planet IX Dashboard 什么是 Planet IX Planet IX&#xff0c;一个由原生 IX TOKEN 推动的 Web3 玩赚平台。作为一款 GameFi 策略游戏&#xff0c; Planet IX 上的每项资…

ArcgisForJS如何访问Arcgis Server?

文章目录 0.引言1.准备ArcGIS相关工具2.创建含有ArcSDE地理数据库的MXD文件3.注册ArcSDE地理数据库4.发布数据到Arcgis Server5.ArcgisForJS访问ArcGIS Server数据 0.引言 ArcGIS API for JavaScript 是一个用于在Web和移动应用程序中创建交互式地图和地理空间分析应用的库。它…

Prometheus+TDengine集群实现监控体系高可用

背景 为避免再次出现因Prometheus宕机导致业务无法查看历史数据受到影响&#xff0c;准备将Prometheus架构从单节点方式升级为高可用集群方式并将后端存储由本地存储改为远端分布式时序数据库存储。分布式时序数据库采用国产数据库TDengine。 架构 解释&#xff1a;虚线代表P…

【服务器】服务器推荐

一、引言 在数字世界的浪潮中&#xff0c;服务器作为数据存储和处理的基石&#xff0c;其重要性不言而喻。而在这个繁星点点的市场中&#xff0c;雨云以其独特的优势和超高的性价比&#xff0c;逐渐成为众多企业和个人的首选。今天&#xff0c;就让我带你走进雨云的世界&#…