I have a bullet scene that is trying to see of an enemy is in a certain group. the group was made in a enemy wave generator scene. The bullet can interact with the enemy by the name of their node buy not by the scene:

from bullet script in bullet scene

this does not work:

func _on_bullet_body_entered(body):
	if body.is_in_group("marblez"):
		print(body.get_name())
		body.queue_free()

but this does:

func _on_bullet_body_entered(body):
	#if body.is_in_group("marblez"):
	if body.get_name()=="yellow_marble":
		print(body.get_name())
		body.queue_free()

How am I handling the groups wrong?

I got groups to work by adding the group in the yellow_marble scene:

func _ready(): self.add_to_group('marblez')

instead of the adding the instance to the group in the wave generator scene at instancing. So it works at the instance / same scene, I dont get groups or how to reference them from another scene. Or for that matter I maybe thinking of them wrongly. I have been thinking of group as some type of list or 1d array. But I suspect it is not. What is it?

Does this group have to be added on the scene that is being grouped- or do you add a group to another scene and add to that?

That is what I tried creating a group in a parent scene- but then when I checked the objects did not show the group. It was only when I added the group at the current scene. That it worked.

This confuses me.

a month later

Groups work like a tagging system. I typically use them as a way to check how nodes should interact with each other.

Let's say you want to check if the object your player is colliding into is part of the environment or an enemy. We create various scenes for enemies and environments and place each scene into their corresponding groups, either "environment" or "enemy".

Tree, Bush, and Fence scenes are put into group "environment" Spider, Bird, and Dog scenes are put into group "enemy"

Now you go ahead and create a level in your game built with those six different nodes. You place your character into the scene and start running around colliding into things. If you want to know what you are colliding into you could do:

if colliding:
	var name = object_i_collided_with.get_name()
		if name == "Spider" || name == "Bird" || name == "Dog":
			print("GAME OVER")

Or you could check what group the object is in:

if colliding:
	if object_i_collided_with.is_in_group("enemy"):
		print("GAME OVER")
if object_i_collided_with.is_in_group("environment"):
	print(object_i_collided_with.get_name()) #check what player knocked into

Not sure if this is the best explanation on how to use groups, but hopefully it helps a little.