Closed Jomii closed 7 months ago
Thank you for that info. I just confirmed it. Somehow I completely forgot to integrate the consumable components into the save system. The save system gave me some headaches, so I admit that it was a bit rushed in the end. This might be a slightly bigger task to fix, but I'll work on it as soon as I can.
The part regarding part 13 is also worrying. I did change the code that identifies items, and messed up there, as it seems. I'll create a separate issue for that, as this is unrelated to the save game problem.
I figured it out. I did in fact not forget the consumable components. They don't have save/load code because they are stateless and get restored when their parent entity is restored. I assumed that this should fully restore items in the inventory. This is essentially true, but I forgot that the entity
property on components gets automatically set via an @onready
variable. As items that get restored in the inventory don't enter the tree, their entity
remains null
. I solved this by explicitly setting it for consumable components. I'll soon update the corresponding tutorial code.
I tested the fix as well and it works great now, thanks!
Thanks for the tutorial series 🙏 It's been fun following it along! In part 10 however I stumbled upon the following issue.
In part 10 there seems to be an issue with items not having their entities properly set up when loading from a save file.
The game crashes when I try to use a health potion or a scroll in a loaded game.
Steps to reproduce with a health potion:
Invalid call. Nonexistent function 'get_entity_name' in base 'Nil',
on the scripthealing_consumable_component.gd
at line 15 (in theactivate -> MessageLog.send_message
function).Steps to reproduce with a lightning scroll:
Cannot call method 'queue_free' on a null value.
on the scriptconsumable_component.gd
at line 16 (in theconsume
function).I also tested the other scrolls and they also similarly to the lightning scroll crash the game once a valid target has been selected.
I did try to reproduce these in the part 13 project as well but I found I couldn't pick up potions or scrolls there. The message log would just print "There is nothing here to pick up." when standing on top of a potion or a scroll and pressing
g
.