1
- // Copyright 2019-2022 ElgSoft. All rights reserved.
1
+ // Copyright 2019-2023 ElgSoft. All rights reserved.
2
2
// Elg001.ElgEditorScripting - ElgSoft.com
3
3
4
4
5
5
#include " ElgEditorBP_Assets.h"
6
- #include < AssetRegistryModule.h>
6
+ #include " AssetRegistry/ AssetRegistryModule.h"
7
7
#include < AssetToolsModule.h>
8
- #include < AssetData.h>
8
+ #include " AssetRegistry/ AssetData.h"
9
9
#include " Misc/Paths.h"
10
10
#include < Engine/World.h>
11
11
#include " HAL\FileManager.h"
16
16
#include < IContentBrowserSingleton.h>
17
17
#include < HAL/PlatformFilemanager.h>
18
18
19
- #include " ElgEditorBP_UBlueprint.h"
20
19
#include < Editor.h>
21
20
22
21
@@ -35,7 +34,7 @@ void UElgEditorBP_Assets::FixRedirectorsByPath(const FName Path, const bool Recu
35
34
FARFilter assetFilter;
36
35
assetFilter.bRecursivePaths = RecursivePaths;
37
36
assetFilter.PackagePaths .Add (Path);
38
- assetFilter.ClassNames .Add (TEXT ( " ObjectRedirector " ));
37
+ assetFilter.ClassPaths .Add (GetClassPathName ( UObjectRedirector::StaticClass () ));
39
38
40
39
// Query for a list of assets in the selected paths
41
40
TArray<FAssetData> assetList;
@@ -44,12 +43,8 @@ void UElgEditorBP_Assets::FixRedirectorsByPath(const FName Path, const bool Recu
44
43
if (assetList.Num () > 0 )
45
44
{
46
45
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 );
53
48
if (assetData.IsValid () && assetData.IsRedirector ()) {
54
49
auto redirector = CastChecked<UObjectRedirector>(assetData.GetAsset ());
55
50
redirectors.Add (redirector);
@@ -103,7 +98,7 @@ FString UElgEditorBP_Assets::GetAssetDiskPath(const FAssetData& AssetDataStruct)
103
98
if (!AssetDataStruct.IsValid ()) return " " ;
104
99
105
100
const FString PackageName = AssetDataStruct.PackageName .ToString ();
106
- const bool bIsWorldAsset = (AssetDataStruct.AssetClass == UWorld::StaticClass ()-> GetFName ( ));
101
+ const bool bIsWorldAsset = (AssetDataStruct.AssetClassPath == GetClassPathName ( UWorld::StaticClass ()));
107
102
const FString Extension = bIsWorldAsset ? FPackageName::GetMapPackageExtension () : FPackageName::GetAssetPackageExtension ();
108
103
const FString FilePath = FPackageName::LongPackageNameToFilename (PackageName, Extension);
109
104
const FString FullFilePath = FPaths::ConvertRelativePathToFull (FilePath);
@@ -149,8 +144,9 @@ FAssetData UElgEditorBP_Assets::GetAssetDataFromPath(const FString& AssetPath)
149
144
return AssetData;
150
145
}
151
146
147
+ FSoftObjectPath softObjectPath = FSoftObjectPath (AssetPath);
152
148
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(" AssetRegistry" );
153
- AssetData = AssetRegistryModule.Get ().GetAssetByObjectPath (*AssetPath );
149
+ AssetData = AssetRegistryModule.Get ().GetAssetByObjectPath (softObjectPath );
154
150
return AssetData;
155
151
}
156
152
@@ -168,7 +164,7 @@ FString UElgEditorBP_Assets::GetAssetPathFromObject(const UObject* AssetObject)
168
164
if (AssetObject == nullptr ) return path;
169
165
170
166
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 ());
172
168
}
173
169
174
170
void UElgEditorBP_Assets::GetAssetDatasByPath (const TArray<FString>& AssetPaths, TArray<FAssetData>& AssetDatas)
@@ -192,13 +188,13 @@ FString UElgEditorBP_Assets::GetAssetName(const FAssetData& AssetDataStruct)
192
188
FString UElgEditorBP_Assets::GetAssetPath (const FAssetData& AssetDataStruct)
193
189
{
194
190
if (!AssetDataStruct.IsValid ()) return " " ;
195
- return AssetDataStruct.ObjectPath .ToString ();
191
+ return AssetDataStruct.GetSoftObjectPath () .ToString ();
196
192
}
197
193
198
194
bool UElgEditorBP_Assets::IsAssetUWorldType (const FAssetData& AssetDataStruct)
199
195
{
200
196
if (!AssetDataStruct.IsValid ()) return false ;
201
- return (AssetDataStruct.AssetClass == UWorld::StaticClass ()-> GetFName ( ));
197
+ return (AssetDataStruct.AssetClassPath == GetClassPathName ( UWorld::StaticClass ()));
202
198
}
203
199
204
200
UPackage* UElgEditorBP_Assets::GetPackage (const FAssetData& AssetDataStruct)
@@ -498,6 +494,27 @@ FString UElgEditorBP_Assets::NewAssetPathToDiskPath(const FString& InAssetPath,
498
494
return fullFilePath;
499
495
}
500
496
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
+
501
518
#pragma endregion
502
519
503
520
#pragma region DiffAssets
0 commit comments