Files
UnrealEngineUWP/Engine/Source/Editor/AnimGraph/Private/AnimGraphNode_LinkedAnimGraphBase.cpp

617 lines
20 KiB
C++
Raw Permalink Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AnimGraphNode_LinkedAnimGraphBase.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Input/SCheckBox.h"
#include "EdGraphSchema_K2.h"
#include "Kismet2/CompilerResultsLog.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "PropertyHandle.h"
#include "DetailLayoutBuilder.h"
#include "DetailCategoryBuilder.h"
#include "Animation/AnimNode_LinkedInputPose.h"
#include "PropertyCustomizationHelpers.h"
#include "ScopedTransaction.h"
#include "AnimationGraphSchema.h"
#include "Widgets/Layout/SBox.h"
#include "UObject/CoreRedirects.h"
#include "Animation/AnimNode_LinkedAnimGraph.h"
#include "AnimGraphAttributes.h"
BlendSpace 2.0: Blendspace Graph Node Added a new animation graph node that hosts its own UBlendSpaceBase. Modified UBlendSpaceBase to allow for pose links to be evaluated as the sample points. The new blend space graphs can be spawned from existing UBlendSpace and UBlendSpace1D assets, or they can be created from scratch, or they can be converted from existing blendspace player nodes via the context menu. Fixed anim node conversion functions so that their transactions work correctly. Updated FBlueprintEditorUtils::IsGraphNameUnique to allow it to work with any object as the outer, not just UBlueprint. UBlueprint still has a special case for functions and events. This is to support GenerateUniqueGraphName within a scope (e.g. an outer graph). Formalized the concept of 'node sub-graphs' (as well as the composite node pattern a little). Previously a number of known node types that contained sub-graphs (e.g. UK2Node_Composite) had special case logic for dealing with node/graph deletion etc. Now any node can opt into this behaviour via the GetSubGraphs() override. Added status bar readouts for the blendspace grid, so we dont have to stuff the prompts into the tooltip any more. Moved anim BP related APIs out of FBlueprintEditor. They are always used via FAnimationBlueprintEditor. Refactored graph title bar widget creation out into a function to allow other document tab factories to create it. Altered breadcrumb trail click callbacks and SMyBlueprint::ExecuteAction to always JumpToHyperLink rather than calling OpenDocument directly. This allows unknown (to FBlueprintEditor) document types that reference objects to be correctly jumped to using the breadcrumb trail. Derived asset editors (i.e. FAnimationBlueprintEditor) can intercept the JumpToHyperlink call to ensure that the correct document is presented (i.e. the correct tab payload is generated). Instead of making yet another bunch of duplicated code for handling the various alpha blend options, refactored this into FAnimGraphNodeAlphaOptions (for editor code) and FAnimNodeAlphaOptions (for runtime code). Added OnCopyTermDefaultsToDefaultObject for per-node copying of default values from editor node to runtime node, rather than another special-case in the compiler. #rb Jurre.deBaare,Phillip.Kavan [CL 15177316 by Thomas Sarkanen in ue5-main branch]
2021-01-25 08:43:19 -04:00
#include "IAnimBlueprintCopyTermDefaultsContext.h"
Anim node data/compiler refactor Per-node constant data is now held on a generated struct as part of sparse class data. Per-node mutable data (i.e. pin links/property access mappings) is now held on a generated 'mutable data' struct that is compiled as part of the generated class. The anim BP compiler is now extended more conventionally using UAnimBlueprintExtension, derived from UBlueprintExtension. This directly replaces the older 'compiler handler' pattern that was added in an emergency fashion for 4.26. Anim graph nodes now request their required extensions and these are held on the UAnimBlueprint in the UBlueprint::Extensions array. The Extensions array is potentially refreshed with any node addition or removal. The Extensions array is force-refreshed each time an anim BP is compiled for the first time to deal with newly added or removed requirements. Const-corrected a bunch of UAnimInstance/FAnimInstanceProxy APIs that rely on (now truly) const data. Added a split state/constant version of FInputScaleBiasClamp to allow some of its data to be split into constants. Tweaked alignment/ordering of FPoseLinkBase to save a few bytes per pose link. Deprecated FAnimNode_Base::OverrideAsset in favor of a more UAnimGraphNode_Base-based approach. Individual nodes can still have runtime overrides via specific accessors. The new approach will also give us the oppurtunity to override multiple assets per node if required in the future. Moved property access into Engine module & removed event support from it - this was never used. Reworked property access compilation API a little - construction/lifetime was a bit confusing previously. Optimized path used to create UK2Node_StructMemberSet nodes in per-node custom events. When using mutable data, the structure used is large and very sparsely connected (i.e. only a few properties are written) so we only create pins that are actually going to be used, rather than creating all of them and conly connecting a few. Patched the following nodes to use the new data approach: - Asset players (sequences, blendspaces, aim offsets) - Blend lists - Ref poses - Roots #rb Jurre.deBaare, Martin.Wilson, Keith.Yerex [CL 16090510 by Thomas Sarkanen in ue5-main branch]
2021-04-22 04:57:09 -04:00
#include "AnimBlueprintExtension_LinkedAnimGraph.h"
#include "AnimGraphNodeCustomizationInterface.h"
#include "BlueprintNodeTemplateCache.h"
#include "EdGraphSchema_K2_Actions.h"
#define LOCTEXT_NAMESPACE "LinkedAnimGraph"
namespace LinkedAnimGraphGraphNodeConstants
{
FLinearColor TitleColor(0.2f, 0.2f, 0.8f);
}
void UAnimGraphNode_LinkedAnimGraphBase::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);
Ar.UsingCustomVersion(FUE5ReleaseStreamObjectVersion::GUID);
if(Ar.CustomVer(FUE5ReleaseStreamObjectVersion::GUID) < FUE5ReleaseStreamObjectVersion::LinkedAnimGraphMemberReference)
{
// Upgrade name to member reference.
// Note that if the name has changed underneath us, we still cant recover the GUID
// until this asset has its node refreshed & the node is resaved
const FAnimNode_LinkedAnimGraph& RuntimeNode = *GetLinkedAnimGraphNode();
const FName FunctionName = RuntimeNode.GetDynamicLinkFunctionName();
UClass* TargetClass = GetTargetSkeletonClass();
if(FunctionName != NAME_None)
{
if(TargetClass != nullptr)
{
FunctionReference.SetExternalMember(FunctionName, TargetClass);
}
else
{
FunctionReference.SetSelfMember(FunctionName);
}
}
}
}
void UAnimGraphNode_LinkedAnimGraphBase::AllocatePoseLinks()
{
FAnimNode_LinkedAnimGraph& RuntimeNode = *GetLinkedAnimGraphNode();
RuntimeNode.InputPoses.Empty();
RuntimeNode.InputPoseNames.Empty();
for(UEdGraphPin* Pin : Pins)
{
if(!Pin->bOrphanedPin)
{
if (UAnimationGraphSchema::IsPosePin(Pin->PinType))
{
if(Pin->Direction == EGPD_Input)
{
RuntimeNode.InputPoses.AddDefaulted();
RuntimeNode.InputPoseNames.Add(Pin->GetFName());
}
}
}
}
}
FLinearColor UAnimGraphNode_LinkedAnimGraphBase::GetNodeTitleColor() const
{
TOptional<FLinearColor> Color;
UClass* TargetClass = GetTargetClass();
if(TargetClass && TargetClass->ImplementsInterface(UAnimGraphNodeCustomizationInterface::StaticClass()))
{
FEditorScriptExecutionGuard AllowScripts;
Color = IAnimGraphNodeCustomizationInterface::Execute_GetTitleColor(TargetClass->GetDefaultObject());
}
if(!Color.IsSet())
{
return GetDefaultNodeTitleColor();
}
return Color.GetValue();
}
FSlateIcon UAnimGraphNode_LinkedAnimGraphBase::GetIconAndTint(FLinearColor& OutColor) const
{
return FSlateIcon(FAppStyle::GetAppStyleSetName(), "ClassIcon.AnimBlueprint");
}
FText UAnimGraphNode_LinkedAnimGraphBase::GetTooltipText() const
{
TOptional<FText> TooltipText;
UClass* TargetClass = GetTargetClass();
// With a null class, template nodes return an empty string to let the metadata take priority
if(TargetClass == nullptr && FBlueprintNodeTemplateCache::IsTemplateOuter(GetGraph()))
{
return FText::GetEmpty();
}
static const FName NAME_Tooltip(TEXT("Tooltip"));
if(TargetClass && TargetClass->HasMetaData(NAME_Tooltip))
{
TooltipText = TargetClass->GetMetaDataText(NAME_Tooltip);
}
if(!TooltipText.IsSet() || TooltipText.GetValue().IsEmpty())
{
return LOCTEXT("ToolTip", "Runs a linked anim graph in another instance to process animation");
}
return TooltipText.GetValue();
}
FText UAnimGraphNode_LinkedAnimGraphBase::GetMenuCategory() const
{
TOptional<FText> Category;
UClass* TargetClass = GetTargetClass();
static const FName NAME_Category(TEXT("Category"));
if(TargetClass && TargetClass->HasMetaData(NAME_Category))
{
Category = TargetClass->GetMetaDataText(NAME_Category);
}
if(!Category.IsSet() || Category.GetValue().IsEmpty())
{
return LOCTEXT("LinkedAnimGraphCategory", "Animation|Linked Anim Graphs");
}
return Category.GetValue();
}
FText UAnimGraphNode_LinkedAnimGraphBase::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
TOptional<FText> Title;
UClass* TargetClass = GetTargetClass();
static const FName NAME_DisplayName(TEXT("DisplayName"));
if(TargetClass && TargetClass->HasMetaData(NAME_DisplayName))
{
Title = TargetClass->GetMetaDataText(NAME_DisplayName);
}
if(!Title.IsSet() || Title.GetValue().IsEmpty())
{
UAnimBlueprint* TargetAnimBlueprint = TargetClass ? CastChecked<UAnimBlueprint>(TargetClass->ClassGeneratedBy) : nullptr;
const FName TargetAnimBlueprintName = TargetAnimBlueprint ? TargetAnimBlueprint->GetFName() : NAME_None;
const FAnimNode_LinkedAnimGraph& Node = *GetLinkedAnimGraphNode();
FFormatNamedArguments Args;
Args.Add(TEXT("NodeType"), LOCTEXT("Title", "Linked Anim Graph"));
Args.Add(TEXT("TargetClass"), FText::FromName(TargetAnimBlueprintName));
if(TitleType == ENodeTitleType::MenuTitle)
{
Title = LOCTEXT("Title", "Linked Anim Graph");
}
else if(TitleType == ENodeTitleType::ListView)
{
if(TargetClass)
{
Title = FText::Format(LOCTEXT("TitleListFormat", "{TargetClass}"), Args);
}
else
{
Title = LOCTEXT("Title", "Linked Anim Graph");
}
}
else
{
if(TargetClass)
{
Title = FText::Format(LOCTEXT("TitleFormat", "{TargetClass}\n{NodeType}"), Args);
}
else
{
Title = LOCTEXT("Title", "Linked Anim Graph");
}
}
}
return Title.GetValue();
}
void UAnimGraphNode_LinkedAnimGraphBase::ValidateAnimNodeDuringCompilation(USkeleton* ForSkeleton, FCompilerResultsLog& MessageLog)
{
Super::ValidateAnimNodeDuringCompilation(ForSkeleton, MessageLog);
UAnimBlueprint* AnimBP = CastChecked<UAnimBlueprint>(GetBlueprint());
UObject* OriginalNode = MessageLog.FindSourceObject(this);
if(HasInstanceLoop())
{
MessageLog.Error(TEXT("Detected loop in linked instance chain starting at @@ inside class @@"), this, AnimBP->GetAnimBlueprintGeneratedClass());
}
// Check for cycles from other linked instance nodes
TArray<UEdGraph*> Graphs;
AnimBP->GetAllGraphs(Graphs);
const FAnimNode_LinkedAnimGraph& Node = *GetLinkedAnimGraphNode();
// Check we don't try to spawn our own blueprint
if(GetTargetClass() == AnimBP->GetAnimBlueprintGeneratedClass())
{
MessageLog.Error(TEXT("Linked instance node @@ targets instance class @@ which it is inside, this would cause a loop."), this, AnimBP->GetAnimBlueprintGeneratedClass());
}
// Check for compatibility
if(UAnimBlueprint* TargetAnimBP = Cast<UAnimBlueprint>(UBlueprint::GetBlueprintFromClass(GetTargetClass())))
{
if(!AnimBP->IsCompatible(TargetAnimBP))
{
MessageLog.Error(TEXT("Linked instance node @@ targets instance class @@ which is incompatible."), this, GetTargetClass());
}
}
}
void UAnimGraphNode_LinkedAnimGraphBase::CreateOutputPins()
{
Super::CreateOutputPins();
// Grab the SKELETON class here as when we are reconstructed during during BP compilation
// the full generated class is not yet present built.
if(UClass* TargetClass = GetTargetSkeletonClass())
{
if(UFunction* Function = FunctionReference.ResolveMember<UFunction>(TargetClass))
{
// Could have re-resolved to a new member name via GUID
const FAnimNode_LinkedAnimGraph& Node = *GetLinkedAnimGraphNode();
if(Node.GetDynamicLinkFunctionName() != FunctionReference.GetMemberName())
{
HandleFunctionReferenceChanged(FunctionReference.GetMemberName());
}
Function = FBlueprintEditorUtils::GetMostUpToDateFunction(Function);
IterateFunctionParameters(Function, [this](FName InName, FEdGraphPinType InPinType)
{
if(UAnimationGraphSchema::IsPosePin(InPinType))
{
UEdGraphPin* NewPin = CreatePin(EEdGraphPinDirection::EGPD_Input, UAnimationGraphSchema::MakeLocalSpacePosePin(), InName);
NewPin->PinFriendlyName = FText::FromName(InName);
CustomizePinData(NewPin, InName, INDEX_NONE);
}
});
}
}
}
void UAnimGraphNode_LinkedAnimGraphBase::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
bool bRequiresNodeReconstruct = false;
FProperty* ChangedProperty = PropertyChangedEvent.Property;
if(ChangedProperty)
{
if (IsStructuralProperty(ChangedProperty))
{
// Set function reference if node structure changes
const FAnimNode_LinkedAnimGraph& Node = *GetLinkedAnimGraphNode();
UClass* TargetClass = GetTargetSkeletonClass();
FName FunctionName = Node.GetDynamicLinkFunctionName();
if(FunctionName != NAME_None)
{
if(TargetClass != nullptr)
{
FGuid FunctionGuid;
FBlueprintEditorUtils::GetFunctionGuidFromClassByFieldName(FBlueprintEditorUtils::GetMostUpToDateClass(TargetClass), FunctionName, FunctionGuid);
FunctionReference.SetExternalMember(FunctionName, TargetClass, FunctionGuid);
}
else
{
FunctionReference.SetSelfMember(FunctionName);
}
}
else
{
FunctionReference = FMemberReference();
}
bRequiresNodeReconstruct = true;
}
}
if(bRequiresNodeReconstruct)
{
ReconstructNode();
}
}
bool UAnimGraphNode_LinkedAnimGraphBase::HasInstanceLoop()
{
TArray<FGuid> VisitedList;
TArray<FGuid> CurrentStack;
return HasInstanceLoop_Recursive(this, VisitedList, CurrentStack);
}
bool UAnimGraphNode_LinkedAnimGraphBase::HasInstanceLoop_Recursive(UAnimGraphNode_LinkedAnimGraphBase* CurrNode, TArray<FGuid>& VisitedNodes, TArray<FGuid>& NodeStack)
{
if(!VisitedNodes.Contains(CurrNode->NodeGuid))
{
VisitedNodes.Add(CurrNode->NodeGuid);
NodeStack.Add(CurrNode->NodeGuid);
if(UAnimBlueprint* AnimBP = Cast<UAnimBlueprint>(UBlueprint::GetBlueprintFromClass(CurrNode->GetTargetClass())))
{
// Check for cycles from other linked instance nodes
TArray<UEdGraph*> Graphs;
AnimBP->GetAllGraphs(Graphs);
for(UEdGraph* Graph : Graphs)
{
TArray<UAnimGraphNode_LinkedAnimGraphBase*> LinkedInstanceNodes;
Graph->GetNodesOfClass(LinkedInstanceNodes);
for(UAnimGraphNode_LinkedAnimGraphBase* LinkedInstanceNode : LinkedInstanceNodes)
{
// If we haven't visited this node, then check it for loops, otherwise if we're pointing to a previously visited node that is in the current instance stack we have a loop
if((!VisitedNodes.Contains(LinkedInstanceNode->NodeGuid) && HasInstanceLoop_Recursive(LinkedInstanceNode, VisitedNodes, NodeStack)) || NodeStack.Contains(LinkedInstanceNode->NodeGuid))
{
return true;
}
}
}
}
}
NodeStack.Remove(CurrNode->NodeGuid);
return false;
}
void UAnimGraphNode_LinkedAnimGraphBase::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
Super::CustomizeDetails(DetailBuilder);
GenerateExposedPinsDetails(DetailBuilder);
IDetailCategoryBuilder& CategoryBuilder = DetailBuilder.EditCategory(FName(TEXT("Settings")));
// Customize InstanceClass
{
TSharedRef<IPropertyHandle> ClassHandle = DetailBuilder.GetProperty(TEXT("Node.InstanceClass"), GetClass());
ClassHandle->MarkHiddenByCustomization();
FDetailWidgetRow& ClassWidgetRow = CategoryBuilder.AddCustomRow(LOCTEXT("FilterStringInstanceClass", "Instance Class"));
ClassWidgetRow.NameContent()
[
ClassHandle->CreatePropertyNameWidget()
]
.ValueContent()
.MinDesiredWidth(250.0f)
[
SNew(SObjectPropertyEntryBox)
.ObjectPath_UObject(this, &UAnimGraphNode_LinkedAnimGraphBase::GetCurrentInstanceBlueprintPath)
.AllowedClass(UAnimBlueprint::StaticClass())
.NewAssetFactories(TArray<UFactory*>())
.OnShouldFilterAsset(FOnShouldFilterAsset::CreateUObject(this, &UAnimGraphNode_LinkedAnimGraphBase::OnShouldFilterInstanceBlueprint))
.OnObjectChanged(FOnSetObject::CreateUObject(this, &UAnimGraphNode_LinkedAnimGraphBase::OnSetInstanceBlueprint, &DetailBuilder))
];
}
}
void UAnimGraphNode_LinkedAnimGraphBase::GenerateExposedPinsDetails(IDetailLayoutBuilder &DetailBuilder)
{
// We dont allow multi-select here
if(DetailBuilder.GetSelectedObjects().Num() > 1)
{
DetailBuilder.HideCategory(TEXT("Settings"));
return;
}
const FStructProperty* NodeProperty = GetFNodeProperty();
if(NodeProperty == nullptr)
{
return;
}
if(CustomPinProperties.Num() > 0)
{
TSharedRef<IPropertyHandle> NodePropertyHandle = DetailBuilder.GetProperty(NodeProperty->GetFName(), GetClass());
IDetailCategoryBuilder& CategoryBuilder = DetailBuilder.EditCategory(FName(TEXT("Exposable Properties")));
for(int32 OptionalPinIndex = 0; OptionalPinIndex < CustomPinProperties.Num(); ++OptionalPinIndex)
{
const FOptionalPinFromProperty& OptionalProperty = CustomPinProperties[OptionalPinIndex];
// Find the property of our inner class
FProperty* Property = GetPinProperty(OptionalProperty.PropertyName);
if(Property == nullptr)
{
continue;
}
FDetailWidgetRow& PropertyWidgetRow = CategoryBuilder.AddCustomRow(FText::FromString(Property->GetName()));
FName PropertyName = Property->GetFName();
FText PropertyTypeText = GetPropertyTypeText(Property);
FFormatNamedArguments Args;
Args.Add(TEXT("PropertyName"), FText::FromName(PropertyName));
Args.Add(TEXT("PropertyType"), PropertyTypeText);
FText TooltipText = FText::Format(LOCTEXT("PropertyTooltipText", "{PropertyName}\nType: {PropertyType}"), Args);
PropertyWidgetRow.NameContent()
[
SNew(STextBlock)
.Text(FText::FromString(Property->GetName()))
.ToolTipText(TooltipText)
.Font(IDetailLayoutBuilder::GetDetailFont())
];
TSharedPtr<SWidget> BindingWidget = UAnimationGraphSchema::MakeBindingWidgetForPin({ this }, PropertyName, false, true);
if(BindingWidget.IsValid())
{
PropertyWidgetRow.ExtensionContent()
[
BindingWidget.ToSharedRef()
];
}
}
}
}
bool UAnimGraphNode_LinkedAnimGraphBase::IsStructuralProperty(FProperty* InProperty) const
{
return InProperty->GetFName() == GET_MEMBER_NAME_CHECKED(FAnimNode_LinkedAnimGraph, InstanceClass);
}
FString UAnimGraphNode_LinkedAnimGraphBase::GetCurrentInstanceBlueprintPath() const
{
UClass* InstanceClass = GetTargetClass();
if(InstanceClass)
{
UBlueprint* ActualBlueprint = UBlueprint::GetBlueprintFromClass(InstanceClass);
if(ActualBlueprint)
{
return ActualBlueprint->GetPathName();
}
}
return FString();
}
bool UAnimGraphNode_LinkedAnimGraphBase::OnShouldFilterInstanceBlueprint(const FAssetData& AssetData) const
{
// Check recursion
if(AssetData.IsAssetLoaded() && Cast<UBlueprint>(AssetData.GetAsset()) == GetBlueprint())
{
return true;
}
// Check skeleton & flags
FAssetDataTagMapSharedView::FFindTagResult TargetSkeletonResult = AssetData.TagsAndValues.FindTag("TargetSkeleton");
FAssetDataTagMapSharedView::FFindTagResult IsTemplateResult = AssetData.TagsAndValues.FindTag("bIsTemplate");
FAssetDataTagMapSharedView::FFindTagResult BlueprintTypeResult = AssetData.TagsAndValues.FindTag("BlueprintType");
if (TargetSkeletonResult.IsSet())
{
const bool bIsTemplate = IsTemplateResult.IsSet() && IsTemplateResult.Equals(TEXT("True"));
const bool bIsInterface = BlueprintTypeResult.IsSet() && BlueprintTypeResult.Equals(TEXT("BPTYPE_Interface"));
if (UAnimBlueprint* CurrentBlueprint = Cast<UAnimBlueprint>(GetBlueprint()))
{
if (!CurrentBlueprint->IsCompatibleByAssetString(TargetSkeletonResult.GetValue(), bIsTemplate, bIsInterface))
{
return true;
}
}
}
return false;
}
void UAnimGraphNode_LinkedAnimGraphBase::OnSetInstanceBlueprint(const FAssetData& AssetData, IDetailLayoutBuilder* InDetailBuilder)
{
FScopedTransaction Transaction(LOCTEXT("SetInstanceBlueprint", "Set Linked Blueprint"));
Modify();
TSharedRef<IPropertyHandle> ClassHandle = InDetailBuilder->GetProperty(TEXT("Node.InstanceClass"), GetClass());
if(UAnimBlueprint* Blueprint = Cast<UAnimBlueprint>(AssetData.GetAsset()))
{
ClassHandle->SetValue(Blueprint->GetAnimBlueprintGeneratedClass());
}
else
{
ClassHandle->SetValue((UObject*)nullptr);
}
}
FLinearColor UAnimGraphNode_LinkedAnimGraphBase::GetDefaultNodeTitleColor() const
{
return LinkedAnimGraphGraphNodeConstants::TitleColor;
}
FPoseLinkMappingRecord UAnimGraphNode_LinkedAnimGraphBase::GetLinkIDLocation(const UScriptStruct* NodeType, UEdGraphPin* SourcePin)
{
FPoseLinkMappingRecord Record = Super::GetLinkIDLocation(NodeType, SourcePin);
if(Record.IsValid())
{
return Record;
}
else if(SourcePin->LinkedTo.Num() > 0 && SourcePin->Direction == EGPD_Input)
{
const FAnimNode_LinkedAnimGraph& Node = *GetLinkedAnimGraphNode();
check(Node.InputPoses.Num() == Node.InputPoseNames.Num());
// perform name-based logic for input pose pins
if (UAnimGraphNode_Base* LinkedNode = Cast<UAnimGraphNode_Base>(FBlueprintEditorUtils::FindFirstCompilerRelevantNode(SourcePin->LinkedTo[0])))
{
FArrayProperty* ArrayProperty = FindFieldChecked<FArrayProperty>(NodeType, GET_MEMBER_NAME_CHECKED(FAnimNode_LinkedAnimGraph, InputPoses));
int32 ArrayIndex = INDEX_NONE;
if(Node.InputPoseNames.Find(SourcePin->GetFName(), ArrayIndex))
{
check(Node.InputPoses.IsValidIndex(ArrayIndex));
return FPoseLinkMappingRecord::MakeFromArrayEntry(this, LinkedNode, ArrayProperty, ArrayIndex);
}
}
}
return FPoseLinkMappingRecord::MakeInvalid();
}
void UAnimGraphNode_LinkedAnimGraphBase::GetOutputLinkAttributes(FNodeAttributeArray& OutAttributes) const
{
// We have the potential to output ALL registered attributes as we can contain any dynamically-linked graph
const UAnimGraphAttributes* AnimGraphAttributes = GetDefault<UAnimGraphAttributes>();
AnimGraphAttributes->ForEachAttribute([&OutAttributes](const FAnimGraphAttributeDesc& InDesc)
{
OutAttributes.Add(InDesc.Name);
});
}
BlendSpace 2.0: Blendspace Graph Node Added a new animation graph node that hosts its own UBlendSpaceBase. Modified UBlendSpaceBase to allow for pose links to be evaluated as the sample points. The new blend space graphs can be spawned from existing UBlendSpace and UBlendSpace1D assets, or they can be created from scratch, or they can be converted from existing blendspace player nodes via the context menu. Fixed anim node conversion functions so that their transactions work correctly. Updated FBlueprintEditorUtils::IsGraphNameUnique to allow it to work with any object as the outer, not just UBlueprint. UBlueprint still has a special case for functions and events. This is to support GenerateUniqueGraphName within a scope (e.g. an outer graph). Formalized the concept of 'node sub-graphs' (as well as the composite node pattern a little). Previously a number of known node types that contained sub-graphs (e.g. UK2Node_Composite) had special case logic for dealing with node/graph deletion etc. Now any node can opt into this behaviour via the GetSubGraphs() override. Added status bar readouts for the blendspace grid, so we dont have to stuff the prompts into the tooltip any more. Moved anim BP related APIs out of FBlueprintEditor. They are always used via FAnimationBlueprintEditor. Refactored graph title bar widget creation out into a function to allow other document tab factories to create it. Altered breadcrumb trail click callbacks and SMyBlueprint::ExecuteAction to always JumpToHyperLink rather than calling OpenDocument directly. This allows unknown (to FBlueprintEditor) document types that reference objects to be correctly jumped to using the breadcrumb trail. Derived asset editors (i.e. FAnimationBlueprintEditor) can intercept the JumpToHyperlink call to ensure that the correct document is presented (i.e. the correct tab payload is generated). Instead of making yet another bunch of duplicated code for handling the various alpha blend options, refactored this into FAnimGraphNodeAlphaOptions (for editor code) and FAnimNodeAlphaOptions (for runtime code). Added OnCopyTermDefaultsToDefaultObject for per-node copying of default values from editor node to runtime node, rather than another special-case in the compiler. #rb Jurre.deBaare,Phillip.Kavan [CL 15177316 by Thomas Sarkanen in ue5-main branch]
2021-01-25 08:43:19 -04:00
void UAnimGraphNode_LinkedAnimGraphBase::OnCopyTermDefaultsToDefaultObject(IAnimBlueprintCopyTermDefaultsContext& InCompilationContext, IAnimBlueprintNodeCopyTermDefaultsContext& InPerNodeContext, IAnimBlueprintGeneratedClassCompiledData& OutCompiledData)
{
Anim blueprint encapsulation improvements Adds 'template' anim BP concept. These anim BPs have no TargetSkeleton and as such cannot have direct references to animations placed inside of their anim graphs Adds function call support from anim nodes. All anim graph nodes can now call functions when initialized, updated, evaluated or when they first become relevant. Relevancy is established using a new FAnimSubsystemInstance_NodeRelevancy which tracks nodes in a local map, per UAnimInstance, if nodes require it. Functions are displayed on the node if bound, and in the details panel. Added a new override point to FAnimSubsystemInstance to allow for WT init. Moved FMemberReference customization into a public header so it can be used on anim node functions. Wrapped functions up into FAnimNodeFunctionRef structure so they can be re-used more effectively. Converted CallFunction node to use them. Added a couple of simple BP function libraries to demonstrate the use of the new FAnimNodeContext (this is intended to be a generic way of exposing FAnimNode_Base types to script without the node types themselves having to be known to script directly). Added the ability to set exposed properties as 'always dynamic' so they appear in mutable data rather than being merged into constants. This allows for the anim node data API to be changed to be less strict (and more script friendly). Now values can be set in mutable data (via GET_MUTABLE_ANIM_NODE_DATA_PTR) and attempted sets to constant data can be ignored and reported to client code. A few minor crash fixes with edge cases (inc when trying to open an asset editor fails because of a missing skeleton/cancellation). Also fixes an issue where literal linked anim graph/control rig/custom poroperty node inputs didnt get copied #rb Jurre.deBaare,Aaron.Cox #ROBOMERGE-SOURCE: CL 16703644 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v835-16672529) [CL 16703653 by thomas sarkanen in ue5-release-engine-test branch]
2021-06-17 08:59:23 -04:00
Super::OnCopyTermDefaultsToDefaultObject(InCompilationContext, InPerNodeContext, OutCompiledData);
BlendSpace 2.0: Blendspace Graph Node Added a new animation graph node that hosts its own UBlendSpaceBase. Modified UBlendSpaceBase to allow for pose links to be evaluated as the sample points. The new blend space graphs can be spawned from existing UBlendSpace and UBlendSpace1D assets, or they can be created from scratch, or they can be converted from existing blendspace player nodes via the context menu. Fixed anim node conversion functions so that their transactions work correctly. Updated FBlueprintEditorUtils::IsGraphNameUnique to allow it to work with any object as the outer, not just UBlueprint. UBlueprint still has a special case for functions and events. This is to support GenerateUniqueGraphName within a scope (e.g. an outer graph). Formalized the concept of 'node sub-graphs' (as well as the composite node pattern a little). Previously a number of known node types that contained sub-graphs (e.g. UK2Node_Composite) had special case logic for dealing with node/graph deletion etc. Now any node can opt into this behaviour via the GetSubGraphs() override. Added status bar readouts for the blendspace grid, so we dont have to stuff the prompts into the tooltip any more. Moved anim BP related APIs out of FBlueprintEditor. They are always used via FAnimationBlueprintEditor. Refactored graph title bar widget creation out into a function to allow other document tab factories to create it. Altered breadcrumb trail click callbacks and SMyBlueprint::ExecuteAction to always JumpToHyperLink rather than calling OpenDocument directly. This allows unknown (to FBlueprintEditor) document types that reference objects to be correctly jumped to using the breadcrumb trail. Derived asset editors (i.e. FAnimationBlueprintEditor) can intercept the JumpToHyperlink call to ensure that the correct document is presented (i.e. the correct tab payload is generated). Instead of making yet another bunch of duplicated code for handling the various alpha blend options, refactored this into FAnimGraphNodeAlphaOptions (for editor code) and FAnimNodeAlphaOptions (for runtime code). Added OnCopyTermDefaultsToDefaultObject for per-node copying of default values from editor node to runtime node, rather than another special-case in the compiler. #rb Jurre.deBaare,Phillip.Kavan [CL 15177316 by Thomas Sarkanen in ue5-main branch]
2021-01-25 08:43:19 -04:00
UAnimGraphNode_LinkedAnimGraphBase* TrueNode = InCompilationContext.GetMessageLog().FindSourceObjectTypeChecked<UAnimGraphNode_LinkedAnimGraphBase>(this);
FAnimNode_LinkedAnimGraph* DestinationNode = reinterpret_cast<FAnimNode_LinkedAnimGraph*>(InPerNodeContext.GetDestinationPtr());
DestinationNode->NodeIndex = InPerNodeContext.GetNodePropertyIndex();
}
Anim node data/compiler refactor Per-node constant data is now held on a generated struct as part of sparse class data. Per-node mutable data (i.e. pin links/property access mappings) is now held on a generated 'mutable data' struct that is compiled as part of the generated class. The anim BP compiler is now extended more conventionally using UAnimBlueprintExtension, derived from UBlueprintExtension. This directly replaces the older 'compiler handler' pattern that was added in an emergency fashion for 4.26. Anim graph nodes now request their required extensions and these are held on the UAnimBlueprint in the UBlueprint::Extensions array. The Extensions array is potentially refreshed with any node addition or removal. The Extensions array is force-refreshed each time an anim BP is compiled for the first time to deal with newly added or removed requirements. Const-corrected a bunch of UAnimInstance/FAnimInstanceProxy APIs that rely on (now truly) const data. Added a split state/constant version of FInputScaleBiasClamp to allow some of its data to be split into constants. Tweaked alignment/ordering of FPoseLinkBase to save a few bytes per pose link. Deprecated FAnimNode_Base::OverrideAsset in favor of a more UAnimGraphNode_Base-based approach. Individual nodes can still have runtime overrides via specific accessors. The new approach will also give us the oppurtunity to override multiple assets per node if required in the future. Moved property access into Engine module & removed event support from it - this was never used. Reworked property access compilation API a little - construction/lifetime was a bit confusing previously. Optimized path used to create UK2Node_StructMemberSet nodes in per-node custom events. When using mutable data, the structure used is large and very sparsely connected (i.e. only a few properties are written) so we only create pins that are actually going to be used, rather than creating all of them and conly connecting a few. Patched the following nodes to use the new data approach: - Asset players (sequences, blendspaces, aim offsets) - Blend lists - Ref poses - Roots #rb Jurre.deBaare, Martin.Wilson, Keith.Yerex [CL 16090510 by Thomas Sarkanen in ue5-main branch]
2021-04-22 04:57:09 -04:00
void UAnimGraphNode_LinkedAnimGraphBase::GetRequiredExtensions(TArray<TSubclassOf<UAnimBlueprintExtension>>& OutExtensions) const
{
OutExtensions.Add(UAnimBlueprintExtension_LinkedAnimGraph::StaticClass());
}
TSharedPtr<FEdGraphSchemaAction> UAnimGraphNode_LinkedAnimGraphBase::GetEventNodeAction(const FText& ActionCategory)
{
TSharedPtr<FEdGraphSchemaAction_K2Event> NodeAction = MakeShareable(new FEdGraphSchemaAction_K2Event(ActionCategory, GetNodeTitle(ENodeTitleType::ListView), GetTooltipText(), 0));
NodeAction->NodeTemplate = this;
return NodeAction;
}
void UAnimGraphNode_LinkedAnimGraphBase::IterateFunctionParameters(UFunction* InFunction, TFunctionRef<void(const FName&, const FEdGraphPinType&)> InFunc) const
{
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
auto IterateParam = [K2Schema, &InFunc](FProperty* InParam, bool bInPoses)
{
const bool bIsFunctionInput = !InParam->HasAnyPropertyFlags(CPF_OutParm) || InParam->HasAnyPropertyFlags(CPF_ReferenceParm);
if (bIsFunctionInput)
{
FEdGraphPinType PinType;
if(K2Schema->ConvertPropertyToPinType(InParam, PinType))
{
if(UAnimationGraphSchema::IsPosePin(PinType) == bInPoses)
{
InFunc(InParam->GetFName(), PinType);
}
}
}
};
// Iterate poses first, then params
for (TFieldIterator<FProperty> PropIt(InFunction); PropIt && (PropIt->PropertyFlags & CPF_Parm); ++PropIt)
{
IterateParam(*PropIt, true);
}
for (TFieldIterator<FProperty> PropIt(InFunction); PropIt && (PropIt->PropertyFlags & CPF_Parm); ++PropIt)
{
IterateParam(*PropIt, false);
}
}
#undef LOCTEXT_NAMESPACE