How to save/apply instance changes back to PackedScene

Godot Version

4.4

Question

Is there a way to save/apply the instance changes of a packed scene instance to the original packed scene?

For example in my hierarchy the white nodes under “Hud” are changes I made after selecting “Editable children” (i think). Now I want to save those changes back the Hud.tscn file in case I create another instance elsewhere.
If I uncheck “Editable children” I get the warning:

Disabling “editable_instance” will cause all properties of the node to be reverted to their default.

Note: In unity this is the “Apply To Prefab” functionality (docs)

I have found that

  1. “Make Local”
  2. Then “Save Branch as Scene” and overwrite the scene file

gets the job done.

I don’t do this very often. There may be caveats.

You can use this code: Need help adding thousands of item to the build menu through code - #2 by Mahan

When you change parent you can choose instance and pack it for save

That works but a dealbreaker is that it breaks all the references that were pointing to the instance

1 Like

I was hoping to find a cleaner solution that doesn’t require adding code to my nodes

It only needs to be run once, there’s no reason to stay later, so it doesn’t matter at all!

Hmm this is something I want to do often to keep my packed scenes updated. Also I think this code would break the instance references I mentioned in the comment above

For something that keeps the instances like they are in the reference scene, you have to instance them with code, there’s probably no other way.

Note: if you need keep instances up to date, As you said, the code above is not appropriate, but the above method doesn’t break the dependencies, it just creates a new PackedScene file that has no effect on the original and its instances. (It doesn’t matter right now)

In general, the best way to update instanes with reference is to in-instance them with code in _ready(), i.e. the instance is not in the tree before the scene is executed, and becomes an instance each time the scene is loaded.

Example:

func _ready():
    var an_instance = preload("res://path/to/scnen.tcsn").instantate() #i am not sure about function name
    # instance configurations
    add_child(an_instance)
    #... and/or setup other instance(s)