Download

How Async Load a BP-Actor?

Hi everyone. There is a BP actor and a path to it, obtained via DataAsset. There is a logic in GameInstance that should spawn a BP actor through a path. Logic sees the path to the BP-actor, sees the name of the BP-actor, but does not generate the BP-actor. There are no error messages. What could be the problem?


void ATestCustom::SpawnActorAsync(UObject * WorldContextObject, TAssetSubclassOf<AActor> AssetPtr)
{
FStreamableManager& AssetLoader = UAssetManager::GetStreamableManager();
FStringAssetReference Reference = AssetPtr.ToSoftObjectPath();
AssetLoader.RequestAsyncLoad(Reference, FStreamableDelegate::CreateUObject(this, &ATestCustom::CallBack, WorldContextObject, Reference));

}

void ATestCustom::CallBack(UObject * WorldContextObject, FStringAssetReference Reference)
{

AActor* SpawnedActor = nullptr;

UClass* ActorClass = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), nullptr, *(Reference.ToString())));

if (ActorClass != nullptr)
{
// Spawn Actor
SpawnedActor = WorldContextObject->GetWorld()->SpawnActor<AActor>(ActorClass);

GEngine->AddOnScreenDebugMessage(0, 1, FColor::Red, ActorClass->GetName());
}

}