"Condition !is_inside_tree() is true " after Node collision with Area

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ng Chen Hon (Mutated
:warning: Old Version Published before Godot 3 was released.

Hi, I am using Godot Engine for a uni assignment.

In an Area, which has the area_enter signal connected, I try to queue_free() any node after a collision with my Area.

However, an error "Condition !is_inside_tree() is true " shows up in the debugger after each node collision with my Area.

The sample code is as below :

func my_area_on_area_enter(area):
    # check if the parent of the area (the node) is inside tree
    print("Area in tree : ", area.get_parent().is_inside_tree())
    # delete the node (which has an extra area for collision purpose)
    area.get_parent().queue_free()

The Output terminal shows that for each node colliding with my Area, all of them are inside the scene tree but the error of "Condition !is_inside_tree() is true " still appears nevertheless.

I have been googling and checked from godot github repo but I found no solution.

I appreciate greatly if anyone shares possible solution.

The godot version I am using is v2.1.3

Thanks !

Could you, please, provide your scene tree structure?

Dr_TwiSteD | 2017-09-02 07:35

:bust_in_silhouette: Reply From: kidscancode

This kind of thing can happen when youqueue_free()an object during collision checks or a signal callback.

Try changing the line to:

area.get_parent().call_deferred("queue_free")

This will ensure that the body is freed on the next frame, after area_enter processing has completed.