Saving nodes spawned at runtime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi. I’ve been experimenting with the JSON save/load method which kind of works but only if a node already exists in the tree.
What about nodes which get ‘spawned’ (ie, instance + add_child) at runtime? Like when the player creates a building (in a city simulator type of game): the building is a node that gets loaded, instanced, and added at a certain position in 3D. How does one go about saving that instance in that position?
The JSON file does include their names and position coordinates from previous saves, but because when the game starts they have not been instanced yet, they’re not getting loaded.

:bust_in_silhouette: Reply From: njamster

Because when the game starts they have not been instanced yet, they’re not getting loaded

You already identified the problem - what’s stopping you? The solution is pretty obvious: during loading, instance missing nodes based on the stored information. Have you read this section of the documentation?

For some reason I wasn’t able to find the page you just linked. It explains everything, thanks!

Macryc | 2020-04-03 09:08