How do I save position and rotation of an instanced kinematic body?

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

So I create an instance of a kinematic body in the main scene. Then if I switch the scene to menu.tscn and back, stats of a body reset. I thought maybe I could use a script where I could save all of the stats my body have, but what I have multiple bodies and how do I get position and rotation of every single one?
Maybe I should not switch scenes at all? But how do I then create menu?

:bust_in_silhouette: Reply From: GameVisitor

How are you “switching” the scene ?

If you are loading it, whenever a scene is loaded, all previous scenes do not exist and the new one is loaded with its default values / settings. If you are doing this, you need to manually save the data / variable states either in memory thru global scripts or to a file.

You can also check the responses here and here for a similar question.

Also, you could (depending on your case) not change the scene but use a PopupDialog menu, usually used for pause menus.

Hope this helps :slight_smile:

I switch scenes by get_tree().change_scene(), but I think PopupDialog would suit me better

da_dev | 2019-06-09 11:00

:bust_in_silhouette: Reply From: sparkart

If you decide to maintain scene state via file storage, you can use PackedScene.pack(node)

Here’s some documentation that demonstrates this