godot
godot copied to clipboard
Prevent some internal nodes being duplicated
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
I think #84824 fixes the same issue, no?
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
#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.
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
Well, you are right, the script can manage the entire tree, possibly adding additional cases.
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