Loading an asset at runtime

Loot at my answer StaticLoadObject in packaged game - C++ - Epic Developer Community Forums
Or another solution - How to find blueprints by parent BP? - Blueprint - Epic Developer Community Forums

 #include "debugProj.h"
  #include "ShipFunctionLibrary.h"
  #include "Runtime/AssetRegistry/Public/AssetData.h"
  
  
  UShipFunctionLibrary::UShipFunctionLibrary(const class FPostConstructInitializeProperties& PCIP)
      : Super(PCIP)
  {
  
  }
  
  UObject * MyGetAsset(FAssetData & asset) {
      if (!asset.IsValid())
      {
          return NULL;
      }
  
      UObject * Asset = FindObject<UObject>(NULL, *asset.ObjectPath.ToString());
      if (Asset == NULL)
      {
          FString tmpstring = asset.ObjectPath.ToString();
          UObject * InOuter = NULL;
          ResolveName(InOuter, tmpstring, true, true);
          
          GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("Now string is ") + tmpstring);
          if (InOuter) {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Magenta, TEXT("InOuter->GetName is ") + InOuter->GetName());
              Asset = StaticFindObjectFast(UObject::StaticClass(), InOuter, *tmpstring);
          }
          if (Asset) {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Black, TEXT("WOW I Have Load Something with StaticFindObjectFast!") + Asset->GetName());
              return Asset;
          }
          
          Asset = (UObject *)StaticLoadObject(UBlueprint::StaticClass(), NULL, *asset.ObjectPath.ToString());
          if (!Asset)
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT(" FAILED LOAD Object like BLUEPRINT By StaticLoadObject"));
          else {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Blue, TEXT(" LOADED like BLUEPRINT By StaticLoadObject"));
              return Asset;
          }
  
          Asset = (UObject *)StaticLoadObject(UObject::StaticClass(), NULL, *asset.ObjectPath.ToString());
          if (!Asset)
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT(" FAILED LOAD Object like UOBJECT By StaticLoadObject"));
          else {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Blue, TEXT(" LOADED like UOBJECT By StaticLoadObject"));
              return Asset;
          }
  
          Asset = (UObject *)LoadObject<UBlueprint>(NULL, *asset.ObjectPath.ToString());
          if (!Asset)
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT(" FAILED LOAD Object like BLUERPRINT "));
          else {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Blue, TEXT(" LOADED like BLUEPRINT By LoadObject"));
              return Asset;
          }
  
          Asset = LoadObject<UObject>(NULL, *asset.ObjectPath.ToString());
          if (!Asset)
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT(" EVEN FAILED LOAD Object like UOBJECT "));
          else {
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Blue, TEXT(" LOADED like UOBJECT By LoadObject"));
              return Asset;
          }        
      }
  
      return (UObject*)Asset;
  }
  
  TSubclassOf<AShip> UShipFunctionLibrary::GetShip(const FString & name)
  {
      UObjectLibrary * lib = UObjectLibrary::CreateLibrary(AShip::StaticClass(), true, GIsEditor);
      lib->AddToRoot();
      int32 loaded = lib->LoadBlueprintAssetDataFromPath("/Game/Ships");
      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::FromInt(loaded) + TEXT(" objects loaded for lib - ") + name);
  
      TArray<FAssetData> Assets;
      lib->GetAssetDataList(Assets);
      for (int32 i = 0; i < Assets.Num(); ++i) {
          FAssetData& assetData = Assets[i];
          GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Get ship: check obj - ") + assetData.AssetName.ToString());
          if (assetData.AssetName.ToString() == name) {
              GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("AssetFound - ") + assetData.AssetName.ToString());
  
              if (!MyGetAsset(assetData))
                  GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: Failed to load object by GetAsset - ") + assetData.AssetName.ToString());
  
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO Class Name - ") + assetData.GetClass()->GetName());
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO FullName - ") + assetData.GetFullName());
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO AssetClass - ") + assetData.AssetClass.ToString());
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO ObjectPath - ") + assetData.ObjectPath.ToString());
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO IsAssetLoaded - ") + (assetData.IsAssetLoaded() ? FString("YES") : FString("NO")));
              GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("INFO IsValid - ") + (assetData.IsValid() ? FString("YES") : FString("NO")));            
                      //UBlueprint * bp = Cast<UBlueprint>(assetData.GetAsset());
              UBlueprint * bp = Cast<UBlueprint>(MyGetAsset(assetData));
              if (bp) {
                  GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Get ship: bleprint cast done for asset - ") + assetData.AssetName.ToString());
                  if (bp->GeneratedClass->IsChildOf(AShip::StaticClass())) {
                      return *(bp->GeneratedClass);
                  }
                  else {
                      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: Class isn`t cild of AShip- ") + assetData.AssetName.ToString());
                  }
              }
              else {
                  GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Get ship: bleprint cast FAILED for asset - ") + assetData.AssetName.ToString());
              }
          }
      }
      return NULL;
  }