0 votes

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, areashapeentered 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: https://we.tl/t-fzKrglj3x5

Thanks

in Engine by (29 points)

1 Answer

+2 votes
Best answer

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)
by (10,856 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 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 webmaster@godotengine.org with your username.