+1 vote

Hello! I'm making a 3D game about burgers where I have the Ingredients (like bread, burger, cheese, etc.) that are RigidBodies and can be stacked up on top of a Tray (so you have to put the ingredients on the right order, but this is not important for this question).

I have an Area node inside the Tray that detects when an Ingredient intersects with the Tray, and when it does, it executes the following code:

func _on_Area_body_entered(body):
    if body is Ingredient: # Ingredient is inhereted from RigidBody
        body.get_parent().remove_child(body)
        $Ingredients.add_child(body) # Node that serves as a container for ingredients
        body.mode = RigidBody.MODE_STATIC

...and then I get a stack overflow error.

Godot version 3.5.1
in Engine by (94 points)
edited by

Sounds like this might be your problem? There are some workarounds suggested there.

1 Answer

0 votes
Best answer

It looks like when an Ingredient is entering the area, you're adding a child to the Ingredient, which automatically enters the area when it's created. A child is then added to this child, which enters the area, and so on. I might be wrong, it depends what $Ingredients is.

by (1,057 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.