Godot Version
4.2
Question
Hi,
I’ve been trying to create a plug-in to generate a sequence of events. It’s basically a list of components and I’ve been trying to save those as a Scene using the ResourceSaver.
func save(filename, events):
set_ownership(events, events)
var scene = PackedScene.new()
scene.pack(events)
ResourceSaver.save(scene, filename)
Set ownership is basically just a function that goes through all the children and sets the owner to the root node.
func set_ownership(p_owner, node) -> void:
for child in node.get_children():
child.owner = p_owner
set_ownership(p_owner, child)
That works just fine, if I run it as program. When I try to use it as a plug-in though, godot complains: “An incoming node’s name clashes with node already in the scene”.
I’ve tracked the error down and as far as I understand the problem is the following. I have a component as .tscn file like the following:
[gd_scene load_steps=3 format=3 uid=“uid://b802p7ooivsc6”]
[ext_resource type=“StyleBox” uid=“uid://l8xwosy4x2pu” path=“res://addons/test/style_box_normal.tres” id=“1_v2r0y”]
[ext_resource type=“Script” path=“res://addons/test/event_component.gd” id=“2_hwova”][node name=“EventComponent” type=“PanelContainer”]
custom_minimum_size = Vector2(0, 80)
anchors_preset = 10
anchor_right = 1.0
offset_left = -2.0
offset_right = -2.0
grow_horizontal = 2
focus_mode = 1
theme_override_styles/panel = ExtResource(“1_v2r0y”)
script = ExtResource(“2_hwova”)[node name=“HFlowContainer” type=“HFlowContainer” parent=“.”]
layout_mode = 2
When I press a button, a component like this is added to a VBoxContainer. Eventually I save the VBoxContainer, all the childrens “owners” are changed to the VBoxContainer and the scene gets saved.
[gd_scene load_steps=4 format=3]
[ext_resource type=“PackedScene” path=“res://addons/test/event_component.tscn” id=“1_ke0rr”]
[ext_resource type=“StyleBox” path=“res://addons/test/style_box_normal.tres” id=“2_hkqbs”]
[ext_resource type=“Script” path=“res://addons/test/event_component.gd” id=“3_vkc4l”][node name=“@VBoxContainer@10” type=“VBoxContainer”]
layout_mode = 2
size_flags_horizontal = 3[node name=“EventComponent” type=“PanelContainer” parent=“.” instance=ExtResource(“1_ke0rr”)]
custom_minimum_size = Vector2(0, 80)
layout_mode = 2
focus_mode = 1
theme_override_styles/panel = ExtResource(“2_hkqbs”)
script = ExtResource(“3_vkc4l”)[node name=“HFlowContainer” type=“HFlowContainer” parent=“EventComponent”]
layout_mode = 2
As you can see here the file that I saved has an “ExtResource” to the original scene plus the node “HFlowContainer”. I assume that the node “HFlowContainer” is also present in the reference to the PackedScene and will then cause a clash of node names.
I’ve tried removing the “instance=ExtResource(…)” by hand and then it works again, but I don’t know how to save programatically created scenes correctly to prevent it from happenening.
What am I doing wrong?