Invalid call. Nonexistent function 'get_nodes_in_group' in base 'KinematicBody2D (bullet.gd)'.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

Working on game 4. The arkanoid / breakout clone.

I have a “Gun Bat” and it works well, UNTIL the bullet object hits the last brick object. I then get the following error:

Invalid call. Nonexistent function 'get_nodes_in_group' in base 'KinematicBody2D (bullet.gd)'.

Here is the code leading up to that point in the bullet script:

#find out if we hit a brick
if is_colliding():
	var entity = get_collider()
	if entity.get_parent().is_in_group("bricks"):
		#destroy the brick
		entity.get_parent().destroyThisBrick()
		#destroy ourselves
		queue_free()
		#check if the level is over or not (we shot the last brick)
		if get_tree().get_nodes_in_group("bricks").size() <= 1:
			#show the congrats scene
			get_node("/root/gameLevel/levelFinished").showScene()
			get_node("/root/gameLevel/levelFinished").updateLabels()
			#remove any leftover balls
			###################################################
#THIS IS THE BUG, BELOW, FOR SHOOTING THE LAST BRICK AND IT FAILING
			###################################################
			if self.is_inside_tree():
				if get_tree().get_nodes_in_group("balls").size() >= 1:
					var ballList = get_nodes_in_group("balls")
					#/\  Above is the line it errors on  /\
					for i in ballList:
						i.queue_free()

I’m a little confused on this. Any advice would be very much appreciated.

:bust_in_silhouette: Reply From: kidscancode

get_nodes_in_group() is a method of SceneTree. You use it correctly the first time, but the second time, you’re trying to call it on the script object, which is a ‘KinematicBody2D’.
Change to this:

if get_tree().get_nodes_in_group("balls").size() >= 1:
                var ballList = get_tree().get_nodes_in_group("balls")

or you could change it to:

var ballList = get_tree().get_nodes_in_group("balls")
if ballList.size() >= 1:

...buries face into hands and sighs

Thank you. It’s so obvious now I read it. It’s almost embarasing. BUT, I very much appreciate your help. I’ve been at this for days and just didn’t see it.

Robster | 2017-07-25 00:27