Skip to content

Instantly share code, notes, and snippets.

@Aaron1178
Last active August 10, 2021 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aaron1178/8f40880309fa8b1c65d19c9827bb6183 to your computer and use it in GitHub Desktop.
Save Aaron1178/8f40880309fa8b1c65d19c9827bb6183 to your computer and use it in GitHub Desktop.
Unreal Engine Asset Manager and Widget Blueprints in Packaged Builds
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