Creating instances in the editor and for runtime

Godot Version

4.3 Beta 1


I am using a @tool script in the editor (to make a tilemap manager) where I am instantiating various copies of a PackedScene that is passed in.

var instance = base_layer.instantiate()
instance.owner = get_tree().edited_scene_root
set_editable_instance(instance, true)

This works in the editor, but when I attempt to run the game, the instances disappear and I get the following error for all the layers:

Node 'TilemapManager/Layer 1/Terrain 1' was modified from inside an instance, but it has vanished.

How could I avoid this issue and properly instance them for runtime?