Fixed inventory crash when restarting level

This commit is contained in:
MaddoScientisto 2025-05-03 16:24:05 +02:00
commit 68daf9c372
5 changed files with 32 additions and 17 deletions

View file

@ -180,12 +180,22 @@ public partial class PlayerWeaponProvider : Node2D
// Spawn if not present
var spawnedWeapon = SpawnWeapon(itemKey);
if (spawnedWeapon is null)
{
GD.Print($"Tried to spawn weapon {itemKey} but failed because it was null.");
return null;
};
return Equip(spawnedWeapon, force);
}
public Weapon Equip(Weapon weapon, bool force)
{
// When we get here we already have a spawned weapon and it's in the list
if (weapon is null)
{
return null;
}
// Always equip it if there's nothing equipped
if (this.EquippedWeapon is null)