|Topic was automatically imported from the old Question2Answer platform.
I’m having difficulty getting an Area2D to detect bodies instantiated from script. I’m using the below script to instantiate static bodies, and a separate Area2D has a “body_entered” signal wired up to itself. This is the exact same code I used successfully in 3.5, but with instantiate() instead of instance().
var mouse_pos = get_global_mouse_position()
var new_body_packed_scene = load("res://godot_object.tscn")
var new_body = new_body_packed_scene.instantiate()
new_body.global_position = mouse_pos
The Area2D won’t detect bodies instantiated this way. The body entered signal doesn’t fire, nor does the get overlapping bodies method return anything. The bug has nothing to do with masks or layers because the Area2D will detect them if they are instantiated from the editor (i.e. manually placed into the scene tree).
It gets weirder: if I manually toggle ‘monitoring’ off and on during debug then the Area2D will detect all of the bodies inside of it, as if it were just seeing them for the first time. But then it goes back to not detecting new bodies until I toggle again. So for some reason the Area2D isn’t continuously monitoring even though monitoring is set to true.
Here’s a link to a zipped minimal reproduction for Godot.4.0.beta.4 Windows if you wanna take a crack at it.