Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_child method doesn't find a child by name after changing it's parent #93450

Closed
Voaz opened this issue Jun 22, 2024 · 9 comments
Closed

find_child method doesn't find a child by name after changing it's parent #93450

Voaz opened this issue Jun 22, 2024 · 9 comments

Comments

@Voaz
Copy link

Voaz commented Jun 22, 2024

Tested versions

reproducible in v4.2.2.stable.arch_linux

System information

Godot v4.2.2.stable unknown - Manjaro Linux #1 SMP PREEMPT_DYNAMIC Mon Jun 10 09:50:04 UTC 2024 - X11 - GLES3 (Compatibility) - AMD Radeon RX 7600 (radeonsi, navi33, LLVM 17.0.6, DRM 3.57, 6.9.3-3-MANJARO) () - AMD Ryzen 5 5600G with Radeon Graphics (12 Threads)

Issue description

when I print print_debug(player.get_children())
I see
[Head:<Node3D#30349984988>, CollisionShape3D:<CollisionShape3D#30400316699>]
but player.find_child("Head") returns null

Steps to reproduce

Node3D [Car]

  • Camera3D

CharacterBody3D [Player]

  • Node3D [Head]
    • Camera3D

move the CharacterBody3D to the Car (Player.get_parent().remove_child(Player) and Car.add_child(Player))
and set the active camera to Cars camera (not required)
then move Player back to root
try to find Head Player.find_child("Head") -> result is null.

Minimal reproduction project (MRP)

later

@Voaz Voaz changed the title fiund_child method doesn't find a child by name after changing it's parent find_child method doesn't find a child by name after changing it's parent Jun 22, 2024
@AThousandShips
Copy link
Member

AThousandShips commented Jun 22, 2024

Does it work with find_children("Head", "", true, false)?

@Voaz
Copy link
Author

Voaz commented Jun 22, 2024

find_child("Head", "", true, false) says too many arguments, but it works like this (I suppose that what you meant to check): find_child("Head", true, false)

@AThousandShips
Copy link
Member

Meant find_children my bad, but yes find_child("Head", true, false)

@Voaz
Copy link
Author

Voaz commented Jun 22, 2024

got it, I checked also other variants:
find_child("Head", false, false) - works
find_child("Head", true, false) - works
find_child("Head", true, true) - doesn't
find_children("Head", "", false, true) - doesn't
find_children("Head", "", false, false) - works

@AThousandShips
Copy link
Member

Then it's expected, you haven't set the owner, the last argument filters only for owned nodes:

If owned is true, only descendants with a valid owner node are checked.

@Voaz
Copy link
Author

Voaz commented Jun 22, 2024

I see, thank you very much @AThousandShips !
IMO: I have to say that it's counterintuitive. I never before was setting owner and it's unclear why it's true by default in find_child.
it is very contradicting when you clearly see it in the tree but find_child gives you null result nevertheless it IS still a child and it is in the tree but the owner is not set...
if so player.get_children() should also give null result and have a owned argument otherwise it's misleading.

@AThousandShips
Copy link
Member

Please open a proposal for that, this is not a bug, but the argument can't be changed to false by default without breaking compatibility so won't happen in 4.x I'd say

@AThousandShips AThousandShips closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2024
@Voaz
Copy link
Author

Voaz commented Jun 22, 2024

I believe needs to be reopen because the behavior is inconsistent. it's not only about find_child but the whole chain of actions.
if I do the same find_child before changing it's parent - it works. but if I change the parent and then return back to original parent - it doesn't work.

@AThousandShips
Copy link
Member

The owner is reset on changing the parent, everything works as designed, so it's something to discuss as a proposal for changing behaviour, not something that's broken or a bug, see here, if you want the owner to be preserved use reparent instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants