godot icon indicating copy to clipboard operation
godot copied to clipboard

Prevent some internal nodes being duplicated

Open AThousandShips opened this issue 1 year ago • 6 comments
trafficstars

Caused by duplication of on-demand created children, for example:

var cpb := ColorPickerButton.new()
print(cpb.get_child_count(true))
print(cpb.get_popup())
print(cpb.get_child_count(true))

var cpb2 := cpb.duplicate()
print(cpb2.get_child_count(true))
print(cpb2.get_popup())
print(cpb2.get_child_count(true))

Will print:

0
@PopupPanel@...:<PopupPanel#...>
1
1
@PopupPanel@...:<PopupPanel#...>
2

This fixes these

There are probably some other potential cases but unsure how to apply each, but keeping these specific menu cases for now

AThousandShips avatar Feb 08 '24 20:02 AThousandShips

I think #84824 fixes the same issue, no?

KoBeWi avatar Feb 08 '24 20:02 KoBeWi

It does not, I tried it with at least some cases, will confirm but that is for instanced nodes I believe

Edit: It does not solve this issue

AThousandShips avatar Feb 08 '24 21:02 AThousandShips

#84824 solves the case when copying sub-scenes. The case here is the case of internal nodes in the same scene.

Internal nodes are usually added when the parent node is initialized or under certain conditions. They can be treated as part of the parent node.

https://github.com/godotengine/godot/blob/94dbf69f5d6b7d2fd9561692df2e71557607fddc/scene/main/node.cpp#L2599-L2607

-       for (int i = 0; i < get_child_count(); i++) {
+       for (int i = 0; i < get_child_count(false); i++) {

It may be better to directly exclude internal nodes when copying.

Rindbee avatar Feb 09 '24 13:02 Rindbee

Some internal nodes might not be automatically added though and might be data independent, unsure, but it'd also break compat to change it for internal nodes IMO as scripts may use it

Note that if they're added in the constructor they are already automatically excluded

AThousandShips avatar Feb 09 '24 13:02 AThousandShips

Well, you are right, the script can manage the entire tree, possibly adding additional cases.

Rindbee avatar Feb 09 '24 14:02 Rindbee

This is still relevant for 4.2 and would be best to get in first IMO, #89442 isn't necessarily cherry-pickable, but I can always retarget it for 4.2

AThousandShips avatar Mar 13 '24 13:03 AThousandShips