1.创建目标actor 蓝图, 创建生成程序c++文件
2.
UObject* SpawnActor = Cast<UObject>(StaticLoadObject(UObject::StaticClass(), NULL, TEXT("/Game/Flags/BP_StoppingFlag_Blueprint.BP_StoppingFlag_Blueprint")));
UWorld* World = GetWorld();
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
World->SpawnActor<AActor>(GeneratedBP->GeneratedClass, GetActorLocation(), GetActorRotation(), SpawnParams);
3.以上代码使用了 StaticLoadObject 在打包测试后发现 无法正常加载蓝图 ,路径会出现问题,如果要程序打包建议使用loadclass
UClass* SpawnActor = LoadClass<AActor>(NULL, TEXT("Blueprint'/Game/Flags/Stopping/BP_StoppingFlag_Blueprint.BP_StoppingFlag_Blueprint_C'"));
将2中loadObject 代码替换为3中代码,打包测试后没出现该问题