area_shape_entered fires twice when collision detected

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

I’m following an example project by packt.com, and I’m having trouble with the collision detection and signal emittion.

The Main Scene contains a Player Scene, and the Coin scene is added in the inspector by adding

   export (PackedScene) Coin

in the MainScene script, for “cloning”. The Player scene when enters any instantiated coin scene, area_shape_entered is detected, on the connected function in Player script the area that enters is filtered by group, if the area is “coin” group, the area’s collision is disabled, the area’s node is queue to end after a tween is played, and a signal is emitted for the score to be increased in the MainScene script, but it seems the collision fires all this twice. To anyone interested helping me with my mistake the project can be downloaded here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

Thanks

:bust_in_silhouette: Reply From: jgodfrey

If you look at the “Errors” tab as you run into a coin, you’ll see this:

area_set_shape_disabled: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.

To fix it, in the coin’s pickup() method, try changing this:

$Collision.disabled = true

To this:

$Collision.set_deferred("disabled", true)