1- // Copyright 2019-2022 ElgSoft. All rights reserved.
1+ // Copyright 2019-2023 ElgSoft. All rights reserved.
22// Elg001.ElgEditorScripting - ElgSoft.com
33
44
55#include " ElgEditorBP_Assets.h"
6- #include < AssetRegistryModule.h>
6+ #include " AssetRegistry/ AssetRegistryModule.h"
77#include < AssetToolsModule.h>
8- #include < AssetData.h>
8+ #include " AssetRegistry/ AssetData.h"
99#include " Misc/Paths.h"
1010#include < Engine/World.h>
1111#include " HAL\FileManager.h"
1616#include < IContentBrowserSingleton.h>
1717#include < HAL/PlatformFilemanager.h>
1818
19- #include " ElgEditorBP_UBlueprint.h"
2019#include < Editor.h>
2120
2221
@@ -35,7 +34,7 @@ void UElgEditorBP_Assets::FixRedirectorsByPath(const FName Path, const bool Recu
3534 FARFilter assetFilter;
3635 assetFilter.bRecursivePaths = RecursivePaths;
3736 assetFilter.PackagePaths .Add (Path);
38- assetFilter.ClassNames .Add (TEXT ( " ObjectRedirector " ));
37+ assetFilter.ClassPaths .Add (GetClassPathName ( UObjectRedirector::StaticClass () ));
3938
4039 // Query for a list of assets in the selected paths
4140 TArray<FAssetData> assetList;
@@ -44,12 +43,8 @@ void UElgEditorBP_Assets::FixRedirectorsByPath(const FName Path, const bool Recu
4443 if (assetList.Num () > 0 )
4544 {
4645 TArray<UObjectRedirector*> redirectors;
47-
48- for (const auto & asset : assetList)
49- {
50- FString path = asset.ObjectPath .ToString ();
51-
52- FAssetData assetData = assetRegistryModule.Get ().GetAssetByObjectPath (*path, false );
46+ for (const auto & asset : assetList) {
47+ FAssetData assetData = assetRegistryModule.Get ().GetAssetByObjectPath (asset.GetSoftObjectPath (), false );
5348 if (assetData.IsValid () && assetData.IsRedirector ()) {
5449 auto redirector = CastChecked<UObjectRedirector>(assetData.GetAsset ());
5550 redirectors.Add (redirector);
@@ -103,7 +98,7 @@ FString UElgEditorBP_Assets::GetAssetDiskPath(const FAssetData& AssetDataStruct)
10398 if (!AssetDataStruct.IsValid ()) return " " ;
10499
105100 const FString PackageName = AssetDataStruct.PackageName .ToString ();
106- const bool bIsWorldAsset = (AssetDataStruct.AssetClass == UWorld::StaticClass ()-> GetFName ( ));
101+ const bool bIsWorldAsset = (AssetDataStruct.AssetClassPath == GetClassPathName ( UWorld::StaticClass ()));
107102 const FString Extension = bIsWorldAsset ? FPackageName::GetMapPackageExtension () : FPackageName::GetAssetPackageExtension ();
108103 const FString FilePath = FPackageName::LongPackageNameToFilename (PackageName, Extension);
109104 const FString FullFilePath = FPaths::ConvertRelativePathToFull (FilePath);
@@ -149,8 +144,9 @@ FAssetData UElgEditorBP_Assets::GetAssetDataFromPath(const FString& AssetPath)
149144 return AssetData;
150145 }
151146
147+ FSoftObjectPath softObjectPath = FSoftObjectPath (AssetPath);
152148 FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(" AssetRegistry" );
153- AssetData = AssetRegistryModule.Get ().GetAssetByObjectPath (*AssetPath );
149+ AssetData = AssetRegistryModule.Get ().GetAssetByObjectPath (softObjectPath );
154150 return AssetData;
155151}
156152
@@ -168,7 +164,7 @@ FString UElgEditorBP_Assets::GetAssetPathFromObject(const UObject* AssetObject)
168164 if (AssetObject == nullptr ) return path;
169165
170166 AssetObject->GetPathName ().Split (" /" , &path, nullptr , ESearchCase::IgnoreCase, ESearchDir::FromEnd);
171- return FString::Printf (TEXT (" %s/%s.%s " ), *path, *AssetObject-> GetName () , *AssetObject->GetName ());
167+ return FString::Printf (TEXT (" %s/%s" ), *path, *AssetObject->GetName ());
172168}
173169
174170void UElgEditorBP_Assets::GetAssetDatasByPath (const TArray<FString>& AssetPaths, TArray<FAssetData>& AssetDatas)
@@ -192,13 +188,13 @@ FString UElgEditorBP_Assets::GetAssetName(const FAssetData& AssetDataStruct)
192188FString UElgEditorBP_Assets::GetAssetPath (const FAssetData& AssetDataStruct)
193189{
194190 if (!AssetDataStruct.IsValid ()) return " " ;
195- return AssetDataStruct.ObjectPath .ToString ();
191+ return AssetDataStruct.GetSoftObjectPath () .ToString ();
196192}
197193
198194bool UElgEditorBP_Assets::IsAssetUWorldType (const FAssetData& AssetDataStruct)
199195{
200196 if (!AssetDataStruct.IsValid ()) return false ;
201- return (AssetDataStruct.AssetClass == UWorld::StaticClass ()-> GetFName ( ));
197+ return (AssetDataStruct.AssetClassPath == GetClassPathName ( UWorld::StaticClass ()));
202198}
203199
204200UPackage* UElgEditorBP_Assets::GetPackage (const FAssetData& AssetDataStruct)
@@ -498,6 +494,27 @@ FString UElgEditorBP_Assets::NewAssetPathToDiskPath(const FString& InAssetPath,
498494 return fullFilePath;
499495}
500496
497+ FTopLevelAssetPath UElgEditorBP_Assets::GetClassPathName (const UClass* InClass)
498+ {
499+ if (InClass) {
500+ return InClass->GetClassPathName ();
501+ }
502+ return FTopLevelAssetPath ();
503+ }
504+
505+ FTopLevelAssetPath UElgEditorBP_Assets::GetObjectPathName (const UObject* InObject)
506+ {
507+ if (InObject) {
508+ return GetClassPathName (InObject->GetClass ());
509+ }
510+ return FTopLevelAssetPath ();
511+ }
512+
513+ FString UElgEditorBP_Assets::FileNameToLongPackageName (const FString InFileName)
514+ {
515+ return FPackageName::FilenameToLongPackageName (InFileName);
516+ }
517+
501518#pragma endregion
502519
503520#pragma region DiffAssets
0 commit comments