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?