0 votes

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://godotengine.org/qa/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?

in Engine by (24 points)
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?

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.

What platform did you test on?

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

ResourceSaver.save returns result.
What value returns?

0 it seems. That bad?

AFAIK 0 stands for OK

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.