• Building
  • Saving game state as PackedScene

Hello everybody, I am struggeling to save my game state, or the state of a single scene.

I am using the Packed_Scene.pack() approach and have set all nodes owners to the scene root wich will be saved.

I encounter the following problems:

-vars of the script want to get reinitialized in the _ready function, I changed everything to init in an own_init() function, so this problem get bypassed

-I've marked all vars in the scenes' script with export hints, so they get saved, sometimes godot crashes with no error, especially for nodes saved in a var.

-all dynamically added child nodes won't get saved, although their owner is set

-all other child nodes load in their initial state - the current position of sprites, their modulate, everything is lost

Since somehow it is not intuitive how this concept of using PackedScenes.pack(stufftosave) should be used, can anybody tell me a workflow of how to save a random, complex scene in its current state? I am fine with reinitializing stuff that changed, I just don't know how godots' concept is supposed to work.

For me it is not obvious at all why certain export vars cause crashes while others don't, why added children won't get saved and also the properties of the original scenes children.

I'd be very thankful if someone could line out what kind of things need to be saved seperately and why a loaded packed scene can't find its subnotes anymore.

Here my steps to see what I tried so far: My root (Game) I ll try to save the currentGame... Node

My code to save and load, with a recursive function to set all owners of the node that I ll save Globalscenes.Kapitel1 points to the currentGame... node

The way the scene will get added again

parts of the scene, it is inherited

It will show up, but in its initial state. Child nodes which I added during the game play are missing. also the positions of the nodes are reset. Other errors occur when I try to drag and drop, since it can't find its children anymore.

Thanks in advance!

This discussion was caught in the moderation queue since you have not confirmed your account yet.

Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.

(Note: You do not need to repost, the discussion has been moved out and is visible now)

If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile:

6 days later

I gave up on the above approach and used a dictionary to serialise what I needed.