NewObject from FAssetData class

While creating an on demand loading system I have encountered a small problem and I can’t find any info on it in the documentation. Basically at some point in the game I get an FAssetData array that contain paths to blueprint classes with default variables. And I want to create an UObject from it with those default variables. Yet the variables are empty.

    UObject * Object = asset.GetAsset();
    UMeshData * MeshObject = Cast<UMeshData>(Object);
    UMeshData * Mesh = NewObject<UMeshData>(MeshObject->StaticClass());
    
    or 

   UObject * Object = asset.GetAsset();
    UMeshData * Mesh = NewObject<UMeshData>(Object->StaticClass());

does not work. Any ideas what can be done with it? Or maybe there is another way to load blueprint classes to memory and then creating objects from them?

Assets are not classes, they are object images which you can load, so you can not use them as classes… but you can use them as templates, bot NewObject and SpawnActor (in FActorSpawnParameters argument) have Template argument which makes new created object use as defaults

Finally got it done. Here is a basic sync loading version for future strugglers:

UAssetManager& AssetManager = UAssetManager::Get();
TArray<FAssetData> AssetDataList;
AssetManager.GetPrimaryAssetDataList(FPrimaryAssetType("MeshDataAsset"), AssetDataList);
for (FAssetData asset : AssetDataList) {
    UObject* LoadedAsset = asset.GetAsset();
    UBlueprint * CastedBP = Cast<UBlueprint>(LoadedAsset);
    if (CastedBP && CastedBP->GeneratedClass->IsChildOf(UMeshData::StaticClass()))
    {
    	UClass * MeshDataClass = *CastedBP->GeneratedClass;
    	UMeshData * Mesh = NewObject<UMeshData>(this, MeshDataClass);
    {
{

The problem was that asset.GetAsset() returns you not the class of the blueprint, but the blueprint itself. So you need to cast it and get the generated class from it. (works like a charm in editor, needs to be tested in cooked)

This way you can load ingame items/dataobjects in a list. Each is a blueprint with a c++ class parent. Also this can be easily updated for async load