Files
integration/Plugins/UEWingman/Source/UEWingman/Handlers/Blueprint_Reparent.h

64 lines
1.8 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingUtils.h"
#include "WingTypes.h"
#include "WingServer.h"
#include "Engine/Blueprint.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "Kismet2/KismetEditorUtilities.h"
#include "Blueprint_Reparent.generated.h"
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
UCLASS()
class UWing_Blueprint_Reparent : public UObject, public IWingHandler
{
GENERATED_BODY()
public:
UPROPERTY(meta=(Description="Blueprint package path"))
FString Blueprint;
UPROPERTY(meta=(Description="New parent class"))
FString Parent;
virtual FString GetDescription() const override
{
return TEXT("Change a Blueprint's parent class.");
}
virtual void Handle() override
{
// Load Blueprint
WingFetcher F;
UBlueprint* BP = F.Asset(Blueprint).Cast<UBlueprint>();
if (!BP) return;
// Find the new parent class by short type name
UClass* NewParentClassObj = UWingTypes::TextToOneObjectType(Parent);
if (!NewParentClassObj) return;
// Validate reparent
if (!WingUtils::CanReparentBlueprint(BP->GeneratedClass, NewParentClassObj))
{
UWingServer::Printf(TEXT("Error: Cannot reparent %s to %s — incompatible class hierarchy.\n"),
*WingUtils::FormatName(BP), *WingUtils::FormatName(NewParentClassObj));
return;
}
// Perform reparent
BP->ParentClass = NewParentClassObj;
FBlueprintEditorUtils::RefreshAllNodes(BP);
FKismetEditorUtilities::CompileBlueprint(BP);
UWingServer::Printf(TEXT("Reparented %s -> %s\n"),
*WingUtils::FormatName(BP), *WingUtils::FormatName(NewParentClassObj));
}
};