Saved PackedScene is not the same as original - misunderstanding about ownership perhaps ?

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

When loading a previously saved PackedScene, I do not get the same scene as the original.

I have the following node tree …

  • InstancedScenes

The following script is attached to the Spatial node

extends Spatial

const MyScene = preload("res://MyScene.tscn")

onready var node_to_be_packed = $InstancedScenes

func _ready():

#Create an arbitary sequence of instances of MyScene of different size
	for offset in range(0,4):
		var this_scene = MyScene.instance()
  		this_scene.get_node("MeshInstance").translation = Vector3(0.0, 0.0, 1.5*float(offset))
		this_scene.get_node("MeshInstance").mesh.size = Vector3(0.5, 0.1, 0.1+0.2*float(offset))

#For convenience, to visualise the result
	var this_camera =
	this_camera.translation = Vector3(1.0,3.0,6.0)
	this_camera.rotation_degrees = Vector3(-45.0, 0.0, 0.0)

#Now recursively assign 'node_to_be_packed' as the owner for all sub-nodes
	set_node_owner(node_to_be_packed, node_to_be_packed)

#And save the packed scene
	var package =
	var _result = package.pack(node_to_be_packed)
	var _error ="res://packedscene.tscn", package)

#Recursive function to set node owner for all sub-nodes
func set_node_owner(this_node:Node, node_owner:Node)->void:
	for child in this_node.get_children():
		child.owner = node_owner
		set_node_owner(child, node_owner)

Where “MyScene” is simply a default CubeMesh, saved as a separate scene.

The resulting PackedScene, when saved, copied to a new project and instantiated via the editor, includes not only the desired instanced scenes, but also an instance of the original unmodified MyScene. I assume because I am not correctly assigning ownership, but I have not been able to solve the problem.

Any help appreciated, thanks