F14.SpawnActorFromClass
小于 1 分钟
简单实例
角色按1生成一个球
cpp
//获取玩家ActorforwardVector
FVector forwardVector = GetActorForwardVector();
//获取玩家ActorLocation
FVector location = GetActorLocation();
//ForwardVector*200+Location
FVector const spawnLocation = forwardVector * 200 + location;
UWorld* const World = GetWorld();
//断言
check(World);
World->SpawnActor<AActor>(CurrentTarget,spawnLocation,FRotator::ZeroRotator);
2024/0803 摘自大佬博客
SpawnActor流程
SpawnActorDeferred 流程
// 延迟生成
AInventoryItemActor* SpawnedItem = GetWorld()->SpawnActorDeferred<AInventoryItemActor>(AInventoryItemActor::StaticClass(),SpawnTransform);
if (SpawnedItem)
{
// 将设置好的数据指针赋值给生成的Actor
SpawnedItem->SetPickUpData(InventoryPickUpData);
// 完成生成
SpawnedItem->FinishSpawning(SpawnTransform);
}