godot icon indicating copy to clipboard operation
godot copied to clipboard

GraphEdit packedScene serialization issue on MenuHbox and connection_lines

Open Azuna1 opened this issue 1 year ago • 5 comments

new-game-project.zip

Tested versions

-Reproducable on Godot 4.3.stable

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 Ti (NVIDIA; 32.0.15.6094) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 Threads)

Issue description

When using a ResourceSaver to save a scene including a GraphEdit, nodes that you reparent to the menu_box as well as all connection_lines are not saved

Steps to reproduce

  1. Create a GraphEdit

var node = Button.new()
node.reparent(get_menu_hbox())

2.b. As for the connection_lines, just create 2 GraphNodes and connect them 4.

self.pack(instance)
ResourceSaver.save(self, "test.tscn")
  1. open test.tscn in text editor and notice missing button and connection lines

Minimal reproduction project (MRP)

new-game-project.zip

Azuna1 avatar Sep 14 '24 21:09 Azuna1

Please upload an MRP to make this easier to test

AThousandShips avatar Sep 15 '24 07:09 AThousandShips

Please upload an MRP to make this easier to test

added in OP edit: sorry had to update the attachment, forgot to adjust owner of the reparented button

Azuna1 avatar Sep 15 '24 08:09 Azuna1

Can confirm the behavior described, but not sure what is expected with the connection lines

CC @Geometror

AThousandShips avatar Sep 16 '24 12:09 AThousandShips

This is not GraphEdit specific. Setting the owners correctly can be a bit tricky in certain cases. The reason that those nodes are not being saved lies in PackedScene::pack: (snippet from SceneState::_parse_node)

//discard nodes that do not belong to be processed
if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
	return OK;
}

See #90823 as it's somewhat relativ and contains some useful information (and maybe a workaround, I haven't checked it).

I'd recommend doing you own serialization on top, since that is required anyway for GraphEdit connections by design.

Geometror avatar Sep 23 '24 09:09 Geometror

This is not GraphEdit specific. Setting the owners correctly can be a bit tricky in certain cases. The reason that those nodes are not being saved lies in PackedScene::pack: (snippet from SceneState::_parse_node)

//discard nodes that do not belong to be processed
if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
	return OK;
}

See #90823 as it's somewhat relativ and contains some useful information (and maybe a workaround, I haven't checked it).

I'd recommend doing you own serialization on top, since that is required anyway for GraphEdit connections by design.

I'm aware of that other issue. However what is the reasoning of an additional serialisation on top? Why is it the way it is, by design? Kind of seems unintentional and missing to on outside view

Azuna1 avatar Sep 23 '24 16:09 Azuna1

Alright, after further investigation I found no clear reason for the current approach, so I went ahead and implemented it in #97449. Still, by handling the serialization manually, you gain the advantage of cleanly separating data from view, which facilitates better modularity and maintainability (depending on your use case of course).

Geometror avatar Sep 25 '24 14:09 Geometror