0 votes

Hi. What to do when I want to load a save file with an object that has been deleted?
When I queue_free() an object, save code can't find it in the tree and engine crashes

What is the correct approach to this problem? "Fake" deleting objects, to delete them permanently just before the next save game?

Here's an example of my .json file:
{"/root/Game/Player2":{"pos":{"x":195.674622, "y":349.674164}},
"/root/Game/Player":{"pos":{"x":850.269409, "y":50.707882}}

Thank you.

in Engine by (39 points)

I downloaded project files of freeware Tanks of Freedom. Dev seems to be saving everything about objects on the map and when loading the game, he erases entire level and builds a new one from the save file. Very interesting stuff for learning Godot out there.

1 Answer

0 votes

Destroying an object from the point of view of the player doesn't means you have to destroy it from programmer's point of view.

If you want to save the fact that a specific object is dead, you should either remember it somewhere when you destroy it, or you can fake delete it by not deleting the node, but making it invisible, stopping its process and removing it from physics layers (so the node is never deleted and also wont have any influence on the game world anymore, but make sure you use this correctly because there is no point in doing this if enemies are infinitely generated for example).

by (28,880 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.