Loading "dead" objects

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MAJOR_KONTROL
:warning: Old Version Published before Godot 3 was released.

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.

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.

MAJOR_KONTROL | 2017-12-11 18:57

:bust_in_silhouette: Reply From: Zylann

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).