godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.13k stars 20.2k forks source link

"add_child" does not work in @exported_storage node #95923

Open GustavoLR548 opened 4 weeks ago

GustavoLR548 commented 4 weeks ago

Tested versions

v4.3.stable.official

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 560.94) - AMD Ryzen 5 5600X 6-Core Processor 3.70 GHz

Issue description

When creating a plugin, you can't use the "add_child" function inside a script in a "export_storage" node, but when recreating this same behavior with the "export" annotation, it works as intended.

For more information, check this video, where I created a MRP explaining my problem

Steps to reproduce

I have made a MRP to help you all to see what I mean, but here is the steps to reproduce the problem.

Minimal reproduction project (MRP)

https://github.com/GustavoLR548/testeexportedstorage

timothyqiu commented 4 weeks ago

When using @export, outro_node references the SpriteSpawner node.

[node name="SpriteSpawnerHolder" parent="." node_paths=PackedStringArray("outro_node") instance=ExtResource("1_1sija")]
outro_node = NodePath("SpriteSpawner")

But with @export_storage, it's creating its own node.

[node name="SpriteSpawnerHolder" parent="." instance=ExtResource("1_1sija")]
outro_node = Object(Node2D,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":0,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"position":Vector2(0, 0),"rotation":0.0,"scale":Vector2(1, 1),"skew":0.0,"script":Resource("res://addons/meuplugin/SpriteSpawner.gd"))

So add_child() is working, the issue is outro_node not referencing the correct node.

GustavoLR548 commented 4 weeks ago

When using @export, outro_node references the SpriteSpawner node.

[node name="SpriteSpawnerHolder" parent="." node_paths=PackedStringArray("outro_node") instance=ExtResource("1_1sija")]
outro_node = NodePath("SpriteSpawner")

But with @export_storage, it's creating its own node.

[node name="SpriteSpawnerHolder" parent="." instance=ExtResource("1_1sija")]
outro_node = Object(Node2D,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":0,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"position":Vector2(0, 0),"rotation":0.0,"scale":Vector2(1, 1),"skew":0.0,"script":Resource("res://addons/meuplugin/SpriteSpawner.gd"))

So add_child() is working, the issue is outro_node not referencing the correct node.

I mean, that is an interesting observation, because it explains why add_child doesn't work, but still, I believe that there is something wrong with @export_storage. Because, it was suppose to create a reference to the "SpriteSpawner" node right? Just like @export did.