apetavern/grubs

Weapon becomes null when you die with it

Closed this issue · 2 comments

  1. Take out a weapon and jump into the water
  2. Open your inventory on another grub and notice the null ref, the weapon that you jumped into the water with is null

Might be the damage zone deleting the weapon?

dch-GH commented

I've investigated this a bit and I think it's due to how the Inventory system works.
When a grub dies to a damagzone:
https://github.com/apetavern/sbox-grubs/blob/948db05459935513a69d6e8930251cf2a2202fb7/code/Player/Grub/Grub.Death.cs#L139
The grub code calls Delete(), which recursively deletes all children. The weapon entity was attached to the grub as a child when the weapon is deployed:
https://github.com/apetavern/sbox-grubs/blob/948db05459935513a69d6e8930251cf2a2202fb7/code/Weapons/Weapon.cs#L103
so it gets deleted.

Possible solutions:

  1. Have a new rule to never actually deleting the Grubs entities until game end, to prevent stuff like this. (Would require adding some functionality to actually handle deaths like this instead of outright deleting. Things like not placing a gravestone, or maybe putting it on top of the water?)
  2. Refactor inventory/weapon code to un-parent and move weapons out from underneath the grubs before they are deleted.
  3. Refactor inventory/weapons to not use entities. (This would be working against the way s&box wants you to develop, would be an uphill battle I think)

I think 1 might be the best way to go. I experimented with 2 but couldn't get it to work. I might investigate it further today to try to really nail down which solution has the best balance of simplicity and robustness.

Thanks for looking into this @Ephememory, I decided to go with the second option you mentioned.
a894fa5