Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | qdmyxwlhx |
if subCate0.has_node("craft_item"):
item0=subCate0.find_child("craft_item")
if not item0:
has_node return true so code run second line successful. but find_child return null which enter the next if block
Need to be mentioned is that this code is in a loop(for) block, the first time run it was works. In the scene_tree l post below, it handle the node named throwingweapon(variable cateSub0) and cobble(named craft_item before)
Would get_node
not acheive what you are trying to do. I looked in the Node documentation and couldn’t find the find_child
function.
godot_dev_ | 2023-01-13 18:34
@godot_dev - note this is a Godot 4-related question.
Node — Godot Engine (latest) documentation in English
jgodfrey | 2023-01-13 19:30
What does your scene tree look like? Specifically, what node is the above script attached to and where is the craft_item
node with respect to it?
jgodfrey | 2023-01-13 19:37
The script attach to an Autoload node so is the child of root. Craft_item is the child of subCate0, they are the part of the UI “desk_panel”. Desk_panel’s path:“root/Main/CanvasLayer/UI/desk_panel”
desk_panel.print_tree() look like(var subCate0 here named weapon):
╴desk_panel
┠╴@@5
┖╴tool
┠╴VSplitContainer
┃ ┠╴throwing_weapon
┃ ┃ ┠╴Label
┃ ┃ ┖╴cobble
┃ ┠╴weapon
┃ ┃ ┠╴Label
┃ ┃ ┖╴craft_item
qdmyxwlhx | 2023-01-14 03:29