Area2D doesn't emit body_entered when a KinematicBody2D spawns inside it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By felipe.canever.f

Hello, everyone!

In my project, when the game runs, I spawn a number of Area2Ds, which I call “food”, randomly around the scene from inside _ready. Inside the same function, I also spawn a number of KinematicBody2Ds, which I call “creatures” and which can move around and gather that food. Both are spawned by instantiating their respective scenes. The creatures “eat” when they come in contact with a piece of food, i.e., when a piece of food emits its body_entered signal connected to that creature. The problem is that, if a creature and a piece of food happen to spawn overlapping each other, the piece of food doesn’t emit body_entered, and the creature gets stuck trying to eat it (it has AI and can move around in search for the nearest piece of food).

Therefore my question is how can I make sure the piece of food emits the signal if it spawns overlapping a creature? Is that a limitation of the physics engine or there is a way I can fix it?

Thanks in advance!

:bust_in_silhouette: Reply From: Inces

You can add a code in “food” ready() function, to iterate through its overlapping_bodies and trigger its collision when any “creature” is found