#include "BlueprintExportSubsystem.h" #include "BlueprintExporter.h" #include "Engine/Blueprint.h" #include "EdGraph/EdGraph.h" #include "UObject/Package.h" #include "Exporters/Exporter.h" #include "UnrealExporter.h" #include "Misc/FileHelper.h" #include "Misc/Paths.h" void UBlueprintExportSubsystem::Initialize(FSubsystemCollectionBase& Collection) { Super::Initialize(Collection); OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddUObject( this, &UBlueprintExportSubsystem::OnAssetSaved); } void UBlueprintExportSubsystem::Deinitialize() { UPackage::PackageSavedWithContextEvent.Remove(OnAssetSavedHandle); Super::Deinitialize(); } void UBlueprintExportSubsystem::OnAssetSaved(const FString& PackageFilename, UPackage* Package, FObjectPostSaveContext Context) { if (!Package) return; FString PkDir = FPaths::ProjectDir() / TEXT("Saved") / TEXT("BlueprintExports") / FPaths::GetBaseFilename(PackageFilename); IFileManager::Get().DeleteDirectory(*PkDir, false, true); // Export the whole package in both formats for comparison. { FStringOutputDevice Archive; const FExportObjectInnerContext InnerContext; UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("copy"), 0); FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("COPY_DUMP.txt"))); } { FStringOutputDevice Archive; const FExportObjectInnerContext InnerContext; UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("t3d"), 0); FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("T3D_DUMP.txt"))); } TArray AllObjects; GetObjectsWithPackage(Package, AllObjects); for (UObject *Obj : AllObjects) { if (UBlueprint *BP = Cast(Obj)) { FString BPDir = PkDir / BP->GetName(); TArray AllGraphs; BP->GetAllGraphs(AllGraphs); for (UEdGraph* Graph : AllGraphs) { MCPGraphExport Exporter(Graph); FString FilePath = BPDir / Graph->GetName() + TEXT(".txt"); FString DetailsPath = BPDir / TEXT("DETAILS") / Graph->GetName() + TEXT(".txt"); FFileHelper::SaveStringToFile(Exporter.GetOutput(), *FilePath); FFileHelper::SaveStringToFile(Exporter.GetDetails(), *DetailsPath); UE_LOG(LogTemp, Warning, TEXT("Blueprint export: %s"), *FilePath); } } } }