Save nested nodes in a new scene at runtime?

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

So I edit an instance of a scene it my game, and I want to save the edits back to the original scene.

This question: https://forum.godotengine.org/903/how-to-save-a-scene-at-run-time?show=907#a907 enabled me to save the scene in the script. However, I have nested nodes in my scene that aren’t saved.

The instanced scene of interest starts of like this:

- gun
    - gun base
        -sprite
       - collisionObject

When I save it, it looks like:

- gun
    - gun base
       - sprite
       - collisionObject
   - newArea2d

It should look like this (notice the nested stuff):

- gun
    - gun base
       - sprite
       - collisionObject
   - newArea2d
       - sprite
       - collisionObject

I tried doing the ‘set_owner’ on the children nodes, setting the owner to be the area.

gun.add_child(new_attachment)
new_attachment.set_owner(gun)	
new_attachment.get_node("Sprite").set_owner(new_attachment)
new_attachment.get_node("CollisionShape2D").set_owner(new_attachment)

var packed_scene = PackedScene.new()
packed_scene.pack(gun)
ResourceSaver.save("res://gun_new.tscn", packed_scene)

But it doesn’t seem to fix it. Any thoughts?

new_attachment.get_node("Sprite").set_owner(new_attachment)
new_attachment.get_node("CollisionShape2D").set_owner(new_attachment)

It seems that these 2 lines are unnecessary.
does not new_attachment already have Sprite and CollistionShape2D?

volzhs | 2016-11-20 22:09

I thought so too, but I’m just trying things based on what the links above said. I used to not have this code, but that doesn’t work either.

Suchaaver Chahal | 2016-11-20 23:42

What platform did you test on?

volzhs | 2016-11-20 23:45

Right now, only Mac. Lemme check it out my linux box. I’ll update this in a second.

Suchaaver Chahal | 2016-11-20 23:45

ResourceSaver.save returns result.
What value returns?

volzhs | 2016-11-20 23:46

0 it seems. That bad?

Suchaaver Chahal | 2016-11-20 23:51

AFAIK 0 stands for OK

volzhs | 2016-11-21 00:48