一、添加代码,修改蓝图类继承的父类
.cpp
#include “Kismet2/BlueprintEditorUtils.h”
#include “Kismet2/KismetEditorUtilities.h”
void UYMToolBPLibrary::ReparentBlueprint(UBlueprint* Blueprint, UClass* NewParentClass)
{
if (!Blueprint || !NewParentClass)
{
UE_LOG(LogTemp, Warning, TEXT("Failed to reparent blueprint!"));
return;
}
if (NewParentClass == Blueprint->ParentClass)
{
UE_LOG(LogTemp, Warning, TEXT("'%s' is already parented to class '%s'!"), *Blueprint->GetFriendlyName(), *NewParentClass->GetName());
return;
}
// There could be possible data loss if reparenting outside the current class hierarchy
if (!Blueprint->ParentClass || !NewParentClass->GetDefaultObject()->IsA(Blueprint->ParentClass))
{
UE_LOG(LogTemp, Warning, TEXT("'%s' class heirarcy is changing, there could be possible data loss!"), *Blueprint->GetFriendlyName());
}
UClass* OriginalParentClass = Blueprint->ParentClass;
Blueprint->ParentClass = NewParentClass;
FBlueprintEditorUtils::RefreshAllNodes(Blueprint);
FBlueprintEditorUtils::MarkBlueprintAsModified(Blueprint);
CompileBlueprint(Blueprint);
}
void UYMToolBPLibrary::CompileBlueprint(UBlueprint* Blueprint)
{
if (Blueprint)
{
// Skip saving this to avoid possible tautologies when saving and allow the user to manually save
EBlueprintCompileOptions Flags = EBlueprintCompileOptions::SkipSave;
FKismetEditorUtilities::CompileBlueprint(Blueprint, Flags);
}
}
UBlueprint* UYMToolBPLibrary::GetBlueprintAsset(UObject* Object)
{
return Cast<UBlueprint>(Object);
}
.h
UFUNCTION(BlueprintCallable, Category = "Blueprint Upgrade Tools")
static void ReparentBlueprint(UBlueprint* Blueprint, UClass* NewParentClass);
UFUNCTION(BlueprintCallable, Category = "Blueprint Upgrade Tools")
static void CompileBlueprint(UBlueprint* Blueprint);
UFUNCTION(BlueprintCallable, Category = "Blueprint Upgrade Tools")
static UBlueprint* GetBlueprintAsset(UObject* Object);
二、在Build.cs文件中加入一下代码
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"BlueprintGraph"
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"UnrealEd",
"AnimGraph"
}
);
三、蓝图中使用方法:
使用的引擎版本:UE4.26
存在问题:当修改父类后提示该蓝图编译失败需要手动编译!!!