[C++]Can not spawn Blueprint when run in packaged game

First Sorry for my poor english.
I want to spawn an Blueprint.
Here is the code:

    auto UOL = UObjectLibrary::CreateLibrary(AActor::StaticClass(),true, GIsEditor);
UOL->AddToRoot();
UOL->LoadBlueprintAssetDataFromPath(TEXT("/Game/TestField/BP/"));
TArray<FAssetData> FADT;
UOL->GetAssetDataList(FADT);
if (FADT.Num() <= 0)
{
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, "AssetFaild");
	return;
}
UBlueprint* bp = Cast<UBlueprint>(FADT[0].GetAsset());
if (bp)
{
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, "CastSucesssful");
	if(GetWorld()->SpawnActor<AActor>(bp->GeneratedClass, FVector(0,0,300), GetActorRotation()))
		GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, "SpawnSucesssful");
}

I find it works fine when game is play in editor.but when I use it in packaged game,the Cast will failed.
I’m sure that the blueprint has been cooked.
How to fix it?

UBlueprint isn’t available at runtime, which is why the cast fails.

You’ll want to get the generated class for the BP using the meta-data from the asset:

if (const FString* GeneratedClassMetaData = FADT[0].TagsAndValues.Find("GeneratedClass"))
{
    const FString ClassPath = FPackageName::ExportTextPathToObjectPath(*GeneratedClassMetaData);
    UClass* BlueprintClass = LoadObject<UClass>(nullptr, *ClassPath);
    // ... BlueprintClass is the same as bp->GeneratedClass in your code
}

Awesome! It works.Thanks a lot!