Hello, Guys
I am using codes below to iterate folder and spawn actor and extract the information and data.
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
TArray<FAssetData> ObjectList;
AssetRegistryModule.Get().GetAssetsByClass(UBlueprint::StaticClass()->GetFName(), ObjectList);
for (auto ObjIter = ObjectList.CreateConstIterator(); ObjIter; ++ObjIter)
{
const FAssetData& Asset = *ObjIter;
UObject* Object = Asset.GetAsset();
UBlueprint* BP = Cast<UBlueprint>(Object);
UClass* AssetClass = BP->GeneratedClass;
FTransform Transform;
FActorSpawnParameters SpawnInfo;
auto World = GEngine->GetWorldContexts()[0].World();
AActor* Actor = nullptr;
if (AssetClass->IsChildOf(AActor::StaticClass()))
{
Actor = World->SpawnActor(AssetClass, &Transform, SpawnInfo);
}
}
it works fine in editor mode and can load all the assets in the folder in disk, but it reports Failed to find object...
in Non-Editor mode(Game mode) and return nullptr. I guess the problem is UObject* Object = Asset.GetAsset();
, because it is implemented with
UObject* Asset = FindObject(NULL, *ObjectPath.ToString());
if ( Asset == NULL )
{
Asset = LoadObject(NULL, *ObjectPath.ToString());
}
but I do not know how to solve it,Could you guys please teach me about that?
Thanks
Bests
YL