Skip to content

Commit c0776e9

Browse files
committed
Exposed AssetDiff to blueprint
Open the AssetDiff between two assets in a project, or a asset in the project vs. an disk path to a uasset file,
1 parent 7c783ec commit c0776e9

5 files changed

Lines changed: 120 additions & 6 deletions

File tree

33 KB
Binary file not shown.
34 KB
Binary file not shown.
Binary file not shown.

Plugins/ElgEditorScripting/Source/ElgEditorScripting/Private/Blueprints/ElgEditorBP_Assets.cpp

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <ContentBrowserModule.h>
1515
#include "Core\Public\Modules\ModuleManager.h"
1616
#include <IContentBrowserSingleton.h>
17+
#include <HAL/PlatformFilemanager.h>
1718

1819

1920
#pragma region Redirectors
@@ -148,10 +149,6 @@ FAssetData UElgEditorBP_Assets::GetAssetDataFromPath(const FString& AssetPath)
148149

149150
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
150151
AssetData = AssetRegistryModule.Get().GetAssetByObjectPath(*AssetPath);
151-
if (!AssetData.IsValid()) {
152-
return AssetData;
153-
}
154-
155152
return AssetData;
156153
}
157154

@@ -200,6 +197,17 @@ FString UElgEditorBP_Assets::GetAssetPath(const FAssetData& AssetDataStruct)
200197

201198
#pragma region GetAssets
202199

200+
void UElgEditorBP_Assets::GetAssetObjectByPath(const FString InAssetPath, UObject*& AssetObject)
201+
{
202+
AssetObject = nullptr;
203+
FAssetData assetData = GetAssetDataFromPath(InAssetPath);
204+
if (assetData.IsValid()) {
205+
AssetObject = assetData.GetAsset();
206+
}
207+
}
208+
209+
210+
203211
void UElgEditorBP_Assets::GetAssetObjects(const TArray<FAssetData>& AssetDataStructs, TArray<UObject*>& AssetObjects)
204212
{
205213
AssetObjects.Empty();
@@ -447,7 +455,6 @@ TArray<FString> UElgEditorBP_Assets::GetSelectedPaths()
447455
}
448456
#pragma endregion
449457

450-
451458
#pragma region Paths
452459

453460
FString UElgEditorBP_Assets::AssetPathToDiskPath(const FString& InAssetPath)
@@ -468,3 +475,79 @@ TArray<FString> UElgEditorBP_Assets::AssetPathsToDiskPaths(TArray<FString> InAss
468475

469476
#pragma endregion
470477

478+
#pragma region DiffAssets
479+
480+
void UElgEditorBP_Assets::DiffAssets(UObject* OldAsset, UObject* NewAsset, const FString OldAssetRevisionString)
481+
{
482+
if (!OldAsset || !NewAsset) {
483+
UE_LOG(LogTemp, Warning, TEXT("Need two valid Asset objects to diff..."));
484+
return;
485+
}
486+
487+
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));
488+
489+
FRevisionInfo OldRevision;
490+
OldRevision.Revision = OldAssetRevisionString;
491+
492+
FRevisionInfo NewRevision;
493+
NewRevision.Revision = TEXT("");
494+
495+
AssetToolsModule.Get().DiffAssets(OldAsset, NewAsset, OldRevision, NewRevision);
496+
}
497+
498+
void UElgEditorBP_Assets::DiffAssetData(const FAssetData OldAsset, const FAssetData NewAsset, const FString OldAssetRevisionString)
499+
{
500+
if (!OldAsset.IsValid() || !NewAsset.IsValid()) {
501+
UE_LOG(LogTemp, Warning, TEXT("Need two valid Asset data to diff..."));
502+
return;
503+
}
504+
UObject* oldAsset = OldAsset.GetAsset();
505+
UObject* newAsset = NewAsset.GetAsset();
506+
DiffAssets(oldAsset, newAsset, OldAssetRevisionString);
507+
}
508+
509+
void UElgEditorBP_Assets::DiffAssetPath(const FString OldAssetPath, const FString NewAssetPath, const FString OldAssetRevisionString)
510+
{
511+
if (OldAssetPath.IsEmpty() || NewAssetPath.IsEmpty()) {
512+
UE_LOG(LogTemp, Warning, TEXT("Need two valid Asset Path to diff..."));
513+
return;
514+
}
515+
FAssetData oldAsset = GetAssetDataFromPath(OldAssetPath);
516+
FAssetData newAsset = GetAssetDataFromPath(NewAssetPath);
517+
DiffAssetData(oldAsset, newAsset, OldAssetRevisionString);
518+
}
519+
520+
void UElgEditorBP_Assets::DiffAssetWithExternalAsset(UObject* NewAsset, const FString ExternalAssetFilePath, const FString ExternalAssetName)
521+
{
522+
if (!NewAsset) {
523+
UE_LOG(LogTemp, Warning, TEXT("Need a valid asset to diff"));
524+
return;
525+
}
526+
if (ExternalAssetName.IsEmpty()) {
527+
UE_LOG(LogTemp, Warning, TEXT("Need a valid ExternalAssetName to diff"));
528+
return;
529+
}
530+
if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*ExternalAssetFilePath)) {
531+
UE_LOG(LogTemp, Warning, TEXT("Failed to find any file at %s"), *ExternalAssetFilePath);
532+
return;
533+
}
534+
535+
FString path = FPaths::ConvertRelativePathToFull(ExternalAssetFilePath);
536+
UPackage* tempPackage = LoadPackage(nullptr, *path, LOAD_ForDiff | LOAD_DisableCompileOnLoad);
537+
if (tempPackage != nullptr) {
538+
UObject* oldObject = FindObject<UObject>(tempPackage, *ExternalAssetName);
539+
if (oldObject != nullptr) {
540+
DiffAssets(oldObject, NewAsset, ExternalAssetName);
541+
}
542+
else {
543+
UE_LOG(LogTemp, Warning, TEXT("Failed to find any asset with name %s in the package"), *ExternalAssetName);
544+
return;
545+
}
546+
} else {
547+
UE_LOG(LogTemp, Warning, TEXT("Failed to load the package at %s"), *path);
548+
return;
549+
}
550+
}
551+
552+
#pragma endregion
553+

Plugins/ElgEditorScripting/Source/ElgEditorScripting/Public/Blueprints/ElgEditorBP_Assets.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class ELGEDITORSCRIPTING_API UElgEditorBP_Assets : public UBlueprintFunctionLibr
125125

126126
#pragma region GetAssetObjects
127127

128+
/* Get the asset object from the asset path */
129+
UFUNCTION(BlueprintPure, Category = "ElgEditor|Asset")
130+
static void GetAssetObjectByPath(const FString InAssetPath, UObject*& AssetObject);
131+
128132
/* Get the asset data as asset objects array*/
129133
UFUNCTION(BlueprintPure, Category = "ElgEditor|Asset")
130134
static void GetAssetObjects(const TArray<FAssetData>& AssetDataStructs, TArray<UObject*>& AssetObjects);
@@ -207,7 +211,6 @@ class ELGEDITORSCRIPTING_API UElgEditorBP_Assets : public UBlueprintFunctionLibr
207211

208212
#pragma endregion
209213

210-
211214
#pragma region Paths
212215

213216
UFUNCTION(BlueprintPure, Category = "ElgEditor|Asset")
@@ -216,6 +219,34 @@ class ELGEDITORSCRIPTING_API UElgEditorBP_Assets : public UBlueprintFunctionLibr
216219
UFUNCTION(BlueprintPure, Category = "ElgEditor|Asset")
217220
static TArray<FString> AssetPathsToDiskPaths(TArray<FString> InAssetPaths);
218221

222+
#pragma endregion
223+
224+
#pragma region DiffAssets
225+
226+
/**
227+
Try and diff two assets using class-specific tool. Will do nothing if either asset is NULL, or they are not the same class.
228+
*/
229+
UFUNCTION(BlueprintCallable, Category = "ElgEditor|Asset|Diff")
230+
static void DiffAssets(UObject* OldAsset, UObject* NewAsset, const FString OldAssetRevisionString);
231+
232+
/**
233+
Try and diff two assets using class-specific tool. Will do nothing if either asset is NULL, or they are not the same class.
234+
*/
235+
UFUNCTION(BlueprintCallable, Category = "ElgEditor|Asset|Diff")
236+
static void DiffAssetData(const FAssetData OldAsset, const FAssetData NewAsset, const FString OldAssetRevisionString);
237+
238+
/**
239+
Try and diff two assets using class-specific tool. Will do nothing if either asset is NULL, or they are not the same class.
240+
*/
241+
UFUNCTION(BlueprintCallable, Category = "ElgEditor|Asset|Diff")
242+
static void DiffAssetPath(const FString OldAssetPath, const FString NewAssetPath, const FString OldAssetRevisionString);
243+
244+
/**
245+
Try and diff two assets using class-specific tool. Will do nothing if either asset is NULL, or they are not the same class.
246+
*/
247+
UFUNCTION(BlueprintCallable, Category = "ElgEditor|Asset|Diff")
248+
static void DiffAssetWithExternalAsset(UObject* NewAsset, const FString ExternalAssetFilePath, const FString ExternalAssetName);
249+
219250
#pragma endregion
220251
};
221252

0 commit comments

Comments
 (0)