Files
integration/Plugins/UEWingman/Deprecated/AnimBlueprint_Create.h

107 lines
3.0 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
2026-03-18 10:17:58 -04:00
#include "WingServer.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "WingPackageMaker.h"
2026-03-08 22:17:14 -04:00
#include "Animation/AnimBlueprint.h"
#include "Animation/AnimBlueprintGeneratedClass.h"
2026-03-09 09:20:46 -04:00
#include "Animation/AnimInstance.h"
2026-03-08 22:17:14 -04:00
#include "Animation/Skeleton.h"
2026-03-10 07:17:42 -04:00
#include "Kismet2/KismetEditorUtilities.h"
2026-03-12 00:44:17 -04:00
#include "AnimBlueprint_Create.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
2026-03-15 19:32:09 -04:00
UCLASS()
2026-03-18 10:17:58 -04:00
class UWing_AnimBlueprint_Create : public UObject, public IWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
2026-03-12 18:31:55 -04:00
UPROPERTY(meta=(Description="Full asset path for the new Animation Blueprint (e.g. '/Game/AnimBP/ABP_Character')"))
FString AssetPath;
2026-03-08 22:17:14 -04:00
2026-03-14 00:02:00 -04:00
UPROPERTY(meta=(Description="Skeleton asset package path"))
2026-03-08 22:17:14 -04:00
FString Skeleton;
UPROPERTY(meta=(Optional, Description="Parent class name (default: AnimInstance)"))
FString ParentClass;
virtual FString GetDescription() const override
{
return TEXT("Create a new Animation Blueprint asset with a specified skeleton.");
}
virtual void Handle() override
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
WingPackageMaker Maker(AssetPath);
2026-03-12 18:31:55 -04:00
if (!Maker.Ok()) return;
2026-03-08 22:17:14 -04:00
// Resolve skeleton
2026-03-18 10:17:58 -04:00
WingFetcher SkeletonFetcher;
2026-03-14 00:02:00 -04:00
USkeleton* SkeletonObj = SkeletonFetcher.Asset(Skeleton).Cast<USkeleton>();
if (!SkeletonObj) return;
2026-03-08 22:17:14 -04:00
// Resolve parent class (default: UAnimInstance)
UClass* ParentClassObj = UAnimInstance::StaticClass();
2026-03-10 07:17:42 -04:00
if (!ParentClass.IsEmpty() && !ParentClass.Equals(TEXT("AnimInstance"), ESearchCase::IgnoreCase))
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
UClass* Found = nullptr;
2026-03-08 22:17:14 -04:00
for (TObjectIterator<UClass> It; It; ++It)
{
2026-03-18 10:17:58 -04:00
if (It->IsChildOf(UAnimInstance::StaticClass()) && WingUtils::Identifies(ParentClass, *It))
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
Found = *It;
2026-03-08 22:17:14 -04:00
break;
}
}
2026-03-10 07:17:42 -04:00
if (!Found)
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("ERROR: Parent class '%s' not found (must derive from AnimInstance)\n"), *ParentClass);
2026-03-13 14:26:04 -04:00
return;
2026-03-10 07:17:42 -04:00
}
ParentClassObj = Found;
2026-03-08 22:17:14 -04:00
}
2026-03-12 18:31:55 -04:00
// Create the package and Animation Blueprint
if (!Maker.Make()) return;
2026-03-08 22:17:14 -04:00
UAnimBlueprint* NewAnimBP = CastChecked<UAnimBlueprint>(
FKismetEditorUtilities::CreateBlueprint(
ParentClassObj,
2026-03-12 18:31:55 -04:00
Maker.Package(),
FName(*Maker.Name()),
2026-03-08 22:17:14 -04:00
BPTYPE_Normal,
UAnimBlueprint::StaticClass(),
UAnimBlueprintGeneratedClass::StaticClass()
));
if (!NewAnimBP)
{
2026-03-18 10:17:58 -04:00
UWingServer::Print(TEXT("ERROR: FKismetEditorUtilities::CreateBlueprint returned null\n"));
2026-03-13 14:26:04 -04:00
return;
2026-03-08 22:17:14 -04:00
}
// Set target skeleton
NewAnimBP->TargetSkeleton = SkeletonObj;
// Compile
2026-03-08 22:17:14 -04:00
FKismetEditorUtilities::CompileBlueprint(NewAnimBP);
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Created: %s\n"), *AssetPath);
UWingServer::Printf(TEXT("ParentClass: %s\n"), *WingUtils::FormatName(ParentClassObj));
2026-03-08 22:17:14 -04:00
2026-03-18 10:17:58 -04:00
TArray<UEdGraph*> Graphs = WingUtils::AllGraphs(NewAnimBP);
2026-03-10 07:17:42 -04:00
for (UEdGraph* Graph : Graphs)
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Graph: %s\n"), *WingUtils::FormatName(Graph));
2026-03-10 07:17:42 -04:00
}
2026-03-08 22:17:14 -04:00
}
};