F21.Spawn actor|带参生成
小于 1 分钟
导言
AEquipmentBase* NewActor = GetWorld()->SpawnActor<AEquipmentBase>(AEquipmentBase::StaticClass());
if (NewActor)
{
NewActor->ItemTag = PickUpStruct.ItemTag;
NewActor->Quantity = PickUpStruct.Quantity;
}
// 使用 SpawnActorDeferred 生成 Actor
AMyActor* NewActor = GetWorld()->SpawnActorDeferred<AMyActor>(AMyActor::StaticClass(), FTransform::Identity);
if (NewActor)
{
// 设置 Actor 的属性
NewActor->ItemTag = ItemTag;
NewActor->Quantity = Quantity;
// 完成 Actor 的生成
NewActor->FinishSpawning(FTransform(SpawnLocation));
}