0 votes
            if subCate0.has_node("craft_item"):
            if not item0:

hasnode return true so code run second line successful. but findchild 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 scenetree l post below, it handle the node named throwingweapon(variable cateSub0) and cobble(named craftitem before)

Godot version 4.0 beta7
in Engine by (21 points)
edited by

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.

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?

The script attach to an Autoload node so is the child of root. Craftitem is the child of subCate0, they are the part of the UI "deskpanel". Deskpanel's path:"root/Main/CanvasLayer/UI/deskpanel"

deskpanel.printtree() look like(var subCate0 here named weapon):

┃ ┠╴throwing
┃ ┃ ┠╴Label
┃ ┃ ┖╴cobble
┃ ┠╴weapon
┃ ┃ ┠╴Label
┃ ┃ ┖╴craft_item

1 Answer

0 votes

l read the doc and find out the reason! l change the code like:


And it works. The thrid arg is owned, doc:

 if owned is true, this method only finds nodes who have an assigned Node.owner.

thx everyone here :)

by (21 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.