Detecting what's inside of an area 2d

Godot Version



I am making a cooking pot in a game and I need to detect was is put (physically) inside of it. i am using get_bodies_entered() and I don’t know how to make an if statement to detect what has entered

Could you show your code? You could use groups

func _on_body_entered(body) -> void:
    if body.is_in_group("Rice"):
    if body.is_in_group("Potato"):
1 Like is also good:

	if == ("turnip"):
1 Like

You could detect them by groups or by class_name (my preferred method)

class_name Pasta

Create a signal connecting from your Area2D/Area3D to your code.
Select the Area node → Node tab → body_entered(body: Node2D)

It will auto generate a function in your code.

func _on_body_entered(body):
  if body is Pasta:
  //Do Something

Just be aware the name variable contains the unique name of the node. If you have more than one instance of the object in game, Godot will auto-generate a unique name for that node.

1 Like