Library.h:
UFUNCTION()
void OnRegistryLoaded();
UFUNCTION(BlueprintCallable
)
static TArray<class UBaseSkillInfo*> GetSkills();
Library.cpp:
ULibrary::ULibrary(const FObjectInitializer& Initializer) : Super(Initializer)
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName("AssetRegistry"));
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
if (AssetRegistry.IsLoadingAssets()) {
AssetRegistry.OnFilesLoaded().AddUObject(this, &ULibrary::OnRegistryLoaded);
}
else {
OnRegistryLoaded();
}
}
void ULibrary::OnRegistryLoaded()
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName("AssetRegistry"));
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
TArray<FAssetData> AssetList;
AssetRegistry.GetAssetsByClass(TEXT("BaseSkillInfo"), AssetList, true);
for (const FAssetData& Asset : AssetList) {
UObject* Obj = Asset.GetAsset();
if (Obj->GetClass()->IsChildOf(UBaseSkillInfo::StaticClass())) {
Skills.AddUnique(Cast<UBaseSkillInfo>(Obj));
}
}
}
TArray<class UBaseSkillInfo*> ULibrary::GetSkills()
{
TArray<class UBaseSkillInfo*> Skills;
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName("AssetRegistry"));
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
TArray<FAssetData> AssetList;
AssetRegistry.GetAssetsByClass(TEXT("BaseSkillInfo"), AssetList, true);
// Split assets into separate arrays.
for (const FAssetData& Asset : AssetList) {
UObject* Obj = Asset.GetAsset();
if (Obj->GetClass()->IsChildOf(UBaseSkillInfo::StaticClass())) {
Skills.AddUnique(Cast<UBaseSkillInfo>(Obj));
}
}
return Skills;
}