get_nodes_in_group returning empty list

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

Very new to godot and am kinda on a time crunch to get my project done so any advice helps! Im trying to make a save file system similar to Tiny Legions on Youtube and whenever I do

var saved_nodes = get_tree().get_nodes_in_group("Saved_Group")

I get an empty list rather than the 3 nodes I know I have in the Saved_Group group. I mightve set my nodes up wrong ? I have a “master node” and under it i have background & character nodes and every example I see always only includes just one node but im not sure.

Edited to fix code formatting.

Are you sure you don’t have a typo (or a character case difference) in the group name?

Do the nodes you expect show up in the Group Editor window (click the Manage Groups button on a node’s Groups tab)

jgodfrey | 2023-03-17 21:25

Screenshot 2023 03 17 at 4 36 06 PM — Postimages

Yeah it should all be saved the same & I see the nodes in the group in the group editor :confused:

nelsontorresjr330 | 2023-03-17 21:38

Also thank you for the pretty edit lol

nelsontorresjr330 | 2023-03-17 21:38

Hmmm… I assume the nodes in that group are part of the scene tree at the time the save_game() function is called? On the surface, I’m not spotting the problem. I’ve run a few quick tests using Godot 4 and get_nodes_in_group() seems to work as expected for me…

jgodfrey | 2023-03-17 21:54

Im not to sure whethre they are or arent part of the scene tree, is there anyway I can manually add them to it prior to calling get_tree() ?

nelsontorresjr330 | 2023-03-17 21:57

I guess it’s not clear to me what you’re doing. Normally, nodes are added to the scene by one of:

  1. Statically, via the editor.
  2. Dynamically during game execution, via instantiate() and add_child() calls.

How are the nodes in question supposed to be added to the scene? If you’re not sure whether they are in the scene or not, you could:

  • Set a break point at the start of your save_game() function
  • Run the game and trigger the save_game function to hit the break point
  • Look at the Remote scene tree to see if the nodes in question are in the scene or not.

Based on the result of your get_node_in_group() call, I assume they are not…

jgodfrey | 2023-03-18 14:44