2020-09-24 00:43:27 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "AnimGraphNode_LinkedAnimGraph.h"
2021-05-24 06:55:32 -04:00
# include "AnimGraphNode_AssetPlayerBase.h"
2021-06-17 08:59:23 -04:00
# include "AnimGraphNode_CallFunction.h"
2021-05-24 06:55:32 -04:00
# include "BlueprintNodeSpawner.h"
2020-09-24 00:43:27 -04:00
# include "Animation/AnimBlueprint.h"
2021-05-24 06:55:32 -04:00
# include "AssetRegistry/AssetRegistryModule.h"
2020-09-24 00:43:27 -04:00
# include "Engine/Blueprint.h"
2021-05-24 06:55:32 -04:00
# include "BlueprintActionDatabaseRegistrar.h"
2021-06-17 08:59:23 -04:00
# include "IAnimBlueprintCopyTermDefaultsContext.h"
# include "KismetCompiler.h"
2021-09-09 11:42:21 -04:00
# include "UObject/UE5MainStreamObjectVersion.h"
2021-05-24 06:55:32 -04:00
# define LOCTEXT_NAMESPACE "UAnimGraphNode_LinkedAnimGraph"
2020-09-24 00:43:27 -04:00
void UAnimGraphNode_LinkedAnimGraph : : PostPasteNode ( )
{
2022-10-26 23:18:44 -04:00
Super : : PostPasteNode ( ) ;
2020-09-24 00:43:27 -04:00
// Clear incompatible target class
if ( UClass * InstanceClass = GetTargetClass ( ) )
{
if ( UAnimBlueprint * LinkedBlueprint = Cast < UAnimBlueprint > ( UBlueprint : : GetBlueprintFromClass ( InstanceClass ) ) )
{
if ( UAnimBlueprint * ThisBlueprint = GetAnimBlueprint ( ) )
{
2021-06-17 08:59:23 -04:00
if ( ! LinkedBlueprint - > bIsTemplate & & ! ThisBlueprint - > bIsTemplate & & LinkedBlueprint - > TargetSkeleton ! = ThisBlueprint - > TargetSkeleton )
2020-09-24 00:43:27 -04:00
{
Node . InstanceClass = nullptr ;
}
}
}
}
2021-05-24 06:55:32 -04:00
}
2021-06-17 08:59:23 -04:00
TArray < UEdGraph * > UAnimGraphNode_LinkedAnimGraph : : GetExternalGraphs ( ) const
{
if ( UClass * InstanceClass = GetTargetClass ( ) )
{
if ( UAnimBlueprint * LinkedBlueprint = Cast < UAnimBlueprint > ( UBlueprint : : GetBlueprintFromClass ( InstanceClass ) ) )
{
for ( UEdGraph * Graph : LinkedBlueprint - > FunctionGraphs )
{
if ( Graph - > GetFName ( ) = = UEdGraphSchema_K2 : : GN_AnimGraph )
{
return { Graph } ;
}
}
}
}
return TArray < UEdGraph * > ( ) ;
}
2021-05-24 06:55:32 -04:00
void UAnimGraphNode_LinkedAnimGraph : : SetupFromAsset ( const FAssetData & InAssetData , bool bInIsTemplateNode )
{
2021-06-17 08:59:23 -04:00
if ( InAssetData . IsValid ( ) )
2021-05-24 06:55:32 -04:00
{
2021-06-17 08:59:23 -04:00
InAssetData . GetTagValue ( " TargetSkeleton " , SkeletonName ) ;
if ( SkeletonName = = TEXT ( " None " ) )
{
SkeletonName . Empty ( ) ;
}
2021-12-08 06:43:16 -05:00
FString TagTemplateValue ;
InAssetData . GetTagValue ( " bIsTemplate " , TagTemplateValue ) ;
bIsTemplateAnimBlueprint = TagTemplateValue . Equals ( TEXT ( " True " ) ) ;
FString BlueprintTypeValue ;
InAssetData . GetTagValue ( " BlueprintType " , BlueprintTypeValue ) ;
bIsInterfaceBlueprint = BlueprintTypeValue . Equals ( TEXT ( " BPTYPE_Interface " ) ) ;
2021-06-17 08:59:23 -04:00
if ( ! bInIsTemplateNode )
{
UAnimBlueprint * AnimBlueprint = CastChecked < UAnimBlueprint > ( InAssetData . GetAsset ( ) ) ;
Node . InstanceClass = AnimBlueprint - > GeneratedClass . Get ( ) ;
2022-09-29 20:38:46 -04:00
}
2021-05-24 06:55:32 -04:00
}
2022-09-29 20:38:46 -04:00
// Set up function reference
FunctionReference . SetExternalMember ( UEdGraphSchema_K2 : : GN_AnimGraph , GetTargetClass ( ) ) ;
2021-05-24 06:55:32 -04:00
}
void UAnimGraphNode_LinkedAnimGraph : : GetMenuActions ( FBlueprintActionDatabaseRegistrar & InActionRegistrar ) const
{
UAnimGraphNode_AssetPlayerBase : : GetMenuActionsHelper (
InActionRegistrar ,
GetClass ( ) ,
{ UAnimBlueprint : : StaticClass ( ) } ,
{ } ,
2021-06-17 12:08:56 -04:00
[ ] ( const FAssetData & InAssetData , UClass * InClass )
2021-05-24 06:55:32 -04:00
{
2021-06-17 08:59:23 -04:00
if ( InAssetData . IsValid ( ) )
{
2021-10-12 21:21:22 -04:00
FText DisplayName ;
InAssetData . GetTagValue ( FBlueprintTags : : BlueprintDisplayName , DisplayName ) ;
if ( ! DisplayName . IsEmpty ( ) )
{
return DisplayName ;
}
else
{
return FText : : Format ( LOCTEXT ( " MenuDescFormat " , " {0} - Linked Anim Graph " ) , FText : : FromName ( InAssetData . AssetName ) ) ;
}
2021-06-17 08:59:23 -04:00
}
2021-10-12 21:21:22 -04:00
return LOCTEXT ( " MenuDesc " , " Linked Anim Graph " ) ;
2021-05-24 06:55:32 -04:00
} ,
2021-06-17 12:08:56 -04:00
[ ] ( const FAssetData & InAssetData , UClass * InClass )
2021-05-24 06:55:32 -04:00
{
2021-06-17 08:59:23 -04:00
if ( InAssetData . IsValid ( ) )
{
2021-10-12 21:21:22 -04:00
FText Description ;
InAssetData . GetTagValue ( FBlueprintTags : : BlueprintDescription , Description ) ;
if ( ! Description . IsEmpty ( ) )
{
return Description ;
}
else
{
2022-09-07 00:40:02 -04:00
return FText : : Format ( LOCTEXT ( " MenuDescTooltipFormat " , " Linked Anim Graph - Runs a linked anim graph in another instance to process animation \n '{0}' " ) , FText : : FromString ( InAssetData . GetObjectPathString ( ) ) ) ;
2021-10-12 21:21:22 -04:00
}
2021-06-17 08:59:23 -04:00
}
else
{
return LOCTEXT ( " MenuDescTooltip " , " Linked Anim Graph " ) ;
}
2021-05-24 06:55:32 -04:00
} ,
[ ] ( UEdGraphNode * InNewNode , bool bInIsTemplateNode , const FAssetData InAssetData )
{
UAnimGraphNode_LinkedAnimGraph * GraphNode = CastChecked < UAnimGraphNode_LinkedAnimGraph > ( InNewNode ) ;
GraphNode - > SetupFromAsset ( InAssetData , bInIsTemplateNode ) ;
2021-10-12 21:21:22 -04:00
} ,
nullptr ,
[ ] ( const FAssetData & InAssetData )
{
if ( InAssetData . IsValid ( ) )
{
FText Category ;
InAssetData . GetTagValue ( FBlueprintTags : : BlueprintCategory , Category ) ;
return Category ;
}
else
{
return FText : : GetEmpty ( ) ;
}
2021-05-24 06:55:32 -04:00
} ) ;
}
bool UAnimGraphNode_LinkedAnimGraph : : IsActionFilteredOut ( class FBlueprintActionFilter const & Filter )
{
bool bIsFilteredOut = false ;
2021-12-08 06:43:16 -05:00
if ( bIsInterfaceBlueprint )
{
bIsFilteredOut = true ;
}
else if ( ! SkeletonName . IsEmpty ( ) )
2021-05-24 06:55:32 -04:00
{
FBlueprintActionContext const & FilterContext = Filter . Context ;
for ( UBlueprint * Blueprint : FilterContext . Blueprints )
{
if ( UAnimBlueprint * AnimBlueprint = Cast < UAnimBlueprint > ( Blueprint ) )
{
2021-12-08 06:43:16 -05:00
if ( ! AnimBlueprint - > IsCompatibleByAssetString ( SkeletonName , bIsTemplateAnimBlueprint , bIsInterfaceBlueprint ) )
2021-05-24 06:55:32 -04:00
{
bIsFilteredOut = true ;
break ;
}
}
else
{
// Not an animation Blueprint, cannot use
bIsFilteredOut = true ;
break ;
}
}
}
return bIsFilteredOut ;
}
2021-09-09 11:42:21 -04:00
void UAnimGraphNode_LinkedAnimGraph : : Serialize ( FArchive & Ar )
{
Super : : Serialize ( Ar ) ;
Ar . UsingCustomVersion ( FUE5MainStreamObjectVersion : : GUID ) ;
if ( Ar . IsLoading ( ) & & Ar . CustomVer ( FUE5MainStreamObjectVersion : : GUID ) < FUE5MainStreamObjectVersion : : AnimGraphNodeTaggingAdded )
{
// Transfer old tag to new system
SetTagInternal ( Node . Tag_DEPRECATED ) ;
}
}
2022-08-19 19:38:25 -04:00
FAnimNode_CustomProperty * UAnimGraphNode_LinkedAnimGraph : : GetCustomPropertyNode ( )
{
FAnimNode_CustomProperty * const RuntimeCustomPropertyNode = GetDebuggedAnimNode < FAnimNode_CustomProperty > ( ) ;
return RuntimeCustomPropertyNode ? RuntimeCustomPropertyNode : & Node ;
}
const FAnimNode_CustomProperty * UAnimGraphNode_LinkedAnimGraph : : GetCustomPropertyNode ( ) const
{
const FAnimNode_CustomProperty * const RuntimeCustomPropertyNode = GetDebuggedAnimNode < FAnimNode_CustomProperty > ( ) ;
return RuntimeCustomPropertyNode ? RuntimeCustomPropertyNode : & Node ;
}
FAnimNode_LinkedAnimGraph * UAnimGraphNode_LinkedAnimGraph : : GetLinkedAnimGraphNode ( )
{
FAnimNode_LinkedAnimGraph * const RuntimeLinkedAnimGraphNode = GetDebuggedAnimNode < FAnimNode_LinkedAnimGraph > ( ) ;
return RuntimeLinkedAnimGraphNode ? RuntimeLinkedAnimGraphNode : & Node ;
}
const FAnimNode_LinkedAnimGraph * UAnimGraphNode_LinkedAnimGraph : : GetLinkedAnimGraphNode ( ) const
{
const FAnimNode_LinkedAnimGraph * const RuntimeLinkedAnimGraphNode = GetDebuggedAnimNode < FAnimNode_LinkedAnimGraph > ( ) ;
return RuntimeLinkedAnimGraphNode ? RuntimeLinkedAnimGraphNode : & Node ;
}
2021-05-24 06:55:32 -04:00
# undef LOCTEXT_NAMESPACE