Last active
August 10, 2021 14:06
-
-
Save Aaron1178/8f40880309fa8b1c65d19c9827bb6183 to your computer and use it in GitHub Desktop.
Unreal Engine Asset Manager and Widget Blueprints in Packaged Builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName("AssetRegistry")); | |
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get(); | |
TArray<FString> ContentPaths; | |
ContentPaths.Add("/Game"); | |
AssetRegistry.ScanPathsSynchronous(ContentPaths, true); | |
// Use the asset registry to get the set of all class names deriving from Base | |
TSet< FName > DerivedNames; | |
{ | |
TArray< FName > BaseNames; | |
BaseNames.Add(UUSERWIDGETBASECLASS::StaticClass()->GetFName()); | |
TSet< FName > Excluded; | |
AssetRegistry.GetDerivedClassNames(BaseNames, Excluded, DerivedNames); | |
} | |
FARFilter Filter; | |
Filter.ClassNames.Add(FName("WidgetBlueprint")); | |
Filter.bRecursivePaths = true; | |
Filter.bRecursiveClasses = true; | |
TArray<FAssetData> AssetList; | |
AssetRegistry.GetAssets(Filter, AssetList); | |
for( FAssetData Asset : AssetList ) | |
{ | |
// Get the the class this blueprint generates (this is stored as a full path) | |
FAssetTagValueRef GeneratedClassPathPtr = Asset.TagsAndValues.FindTag(TEXT("GeneratedClass")); | |
if(GeneratedClassPathPtr.IsSet()) | |
{ | |
// Convert path to just the name part | |
const FString ClassObjectPath = FPackageName::ExportTextPathToObjectPath(GeneratedClassPathPtr.AsString()); | |
const FString ClassName = FPackageName::ObjectPathToObjectName(ClassObjectPath); | |
// Check if this class is in the derived set | |
if(!DerivedNames.Contains(*ClassName)) | |
{ | |
continue; | |
} | |
//Register this PrimaryAsset Widget Blueprint with its PrimaryAssetId and FAssetData | |
AssetManager.RegisterSpecificPrimaryAsset(Asset.GetPrimaryAssetId(), Asset); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment