Godot 4 (alpha 14) - Cannot access groups from or in just one node in the scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GoGoGodot

I have one node that acts like it exists in a different tree or scene than the rest. Groups just suddenly stopped working on it.

Here is my hierarchy:

Problematic Node in scene - imgur.com/NtxtTBd if it doesn't load the image

Groups were working perfectly fine with this node, but I made some script change that has me beyond stumped.

What I’ve tested so far:
get_tree().has_group("Player") returns true(called from this node), but:
get_tree().get_nodes_in_group("Player") returns empty even though any other node seems to be able to retrieve Players in the scene with the same method.
Now if I try to get the problem node via groups with get_tree().get_nodes_in_group("Enemy") from any other node in the scene, it doesn’t show up either. (unless called from itself. It can retrieve itself via groups)

The change did occur around the time I switched players to being instanced instead of already in the scene to start, but now even just including Players in the scene to start doesn’t work and it can’t seem to detect any group outside itself. Rolling back the script attached to it seemed to fix it, but couldn’t pin point what would possibly stop groups from working. I changed agent.set_target_location(get_tree().get_first_node_in_group("Player").get_global_transform().origin) to get_tree().get_nodes_in_group("Player") with a loop over the players, but changing that part back still retrieves nothing now. The rest of the code is pretty much the physics process.

My current workaround: either using paths to the players, or a singleton with references to the players will at least make it work.
example: agent.set_target_location(Global.players[0].position)

-Game is networked
-the problematic node’s script extends the player script

Anyone know why groups might stop working on a specific node in a scene? Thanks for any help, if it comes down to it I can share the project, more code, or try to replicate it in a simplified project.

Well, I rolled back the script and just added parts back in until it was basically the same script. I’m afraid I don’t have an answer if anyone else runs into this except to rollback and test chunk by chunk. The fact that it was fixed by changing my script makes me think it was a user error and not a godot thing. I’ll update if I figure out what I did wrong.

sounds weird. The only thing I can think of is unchilding a node at some point, and leaving it as an orphan.

Inces | 2022-08-26 20:29

It’s not set up to change in the hierarchy at the moment and I’ve tried it in different places in the hierarchy, but I’ll mess around with that. It does seem to be able to use groups if I roll back the code, but I’m not sure which part. I’ve been just swapping chunks in and out, but haven’t found which part is causing it yet. Yeah, super weird. Thanks

GoGoGodot | 2022-08-26 20:49

No, I meant the reason for this error might be orphaned node. Like You might have called remove_child but never deleted it, nor childed somewhere else.
You can use Remote Tab to take a closer look what happens dynamically in scene hierarchy at the time of running project

Inces | 2022-08-26 21:22

I understood, I’m not calling either add or remove child on it though, or otherwise changing the hierarchy around it. It’s where I expect it to be in remote.

Edit: One of the ways I was making it work was accessing the players through their relation in the hierarchy, or other object that had the players as variables.

GoGoGodot | 2022-08-26 21:43

I just reverted and rewrote it. I appreciate the help, thank you.

GoGoGodot | 2022-08-26 22:34