How to area2D an instantiated scene?

Godot Version

4.6

Question

How to check if an instantiated rigidbody enters an are.

If i got it right what godot docs told me then you can only check for the body wich emits the signal to enter Area2D.

I have no idea how to work around i found no solution after ouers of searching youtube and duckduckgo = bes searchtool.

thanks for reading and halping!


Areas have body_entered signal.

what dose receiwet body means?

my body cant recive the signal bc it gets instantiated at runntime.

Emitted when the recived body enters the are.

what is a receiving body? dot it has to do with signal receiving?

I know how to youse signals i am not dome kind of vibecoder who has no clue wht he is doing.

a Node2D is the receiving node of the signal. and her is the code but i do not get it to print : (

extends Node2D


@export var body: PackedScene


func _on_replay_button_pressed() -> void:
	get_tree().reload_current_scene()


func _on_area_2d_2_body_entered(body: RigidBody2D) -> void:
	if (body.name == "ball"):
		print ("winn")

Don’t compare to the node’s name, use a class_name or group for this.

how to youse a class name?

Thank you so much!!!

And sorry for my gramar.

If the ball node has a script, you can add this at the beginning:

class_name Ball

And then check for the class:

if body is Ball:

how dose this loks in my script?

extends Node2D


@export var body: PackedScene


func _on_replay_button_pressed() -> void:
	get_tree().reload_current_scene()


func _on_area_2d_2_body_entered(body: RigidBody2D) -> void:
	if (body.name == "ball"):
		print ("winn")

this dose not work.

extends Node2D


func _on_replay_button_pressed() -> void:
	get_tree().reload_current_scene()


func _on_area_2d_2_body_entered(body: RigidBody2D) -> void:
	if body is ball:
		print ("winn")

btw i am a visual lorner sooo…

The Ball needs a script that starts with something like:

class_name Ball
extends RigidBody2D

Then your Node2D checks for that class_name:

extends Node2D


func _on_replay_button_pressed() -> void:
	get_tree().reload_current_scene()


func _on_area_2d_2_body_entered(body: RigidBody2D) -> void:
	if body is Ball:
		print ("winn")

my ball script is now an class_name but it still dos not print.

signal is conectet fine and layers an masks are god too.

Then try to print something before the if-statement:

func _on_area_2d_2_body_entered(body: RigidBody2D) -> void:
	print("Something detected!")
	if body is Ball:
		print("Ball detected!")

her are some screenshoots

Do you get any prints from this?

nope not a single print massage

Try to enable “Visible Collision Shapes” in the debug menu. Can you see the collision shapes at the expected positions during the game?

Error at (10, 13): Could not find type “ball” in the current scope.

extends Node2D

func _on_replay_button_pressed() → void:get_tree().reload_current_scene()

func _on_area_2d_2_body_entered(body: Node2D) → void:print(“Something detected!”)if body is ball:print (“Ball detected!”)