Add extra checking when spawning WeaponPickup on EnemyAI Death

This commit is contained in:
baz 2023-09-12 23:37:33 +01:00
parent d3cfa1b746
commit 480cfb0530
1 changed files with 6 additions and 4 deletions

View File

@ -104,12 +104,14 @@ void AEnemyAIController::OnDeath(FDamageInfo info)
if (enemy->DefaultWeaponInventory.Num() > 0) if (enemy->DefaultWeaponInventory.Num() > 0)
{ {
// TODO: This can sometimes crash, need to investigate // TODO: This can sometimes crash, need to investigate
auto weaponPickup = GetWorld()->SpawnActor<AWeaponPickup>(); if (auto weaponPickup = GetWorld()->SpawnActor<AWeaponPickup>())
{
weaponPickup->SetActorLocation(enemy->GetActorLocation()); weaponPickup->SetActorLocation(enemy->GetActorLocation());
weaponPickup->SetWeapon(enemy->DefaultWeaponInventory[enemy->GetCurrentInventorySlot()]); weaponPickup->SetWeapon(enemy->DefaultWeaponInventory[enemy->GetCurrentInventorySlot()]);
weaponPickup->SetWeaponProperties(*enemy->CurrentWeapon->GetWeaponProperties()); weaponPickup->SetWeaponProperties(*enemy->CurrentWeapon->GetWeaponProperties());
} }
} }
}
void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors) void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
{ {