How can I disable/enable an Area2D's detection?

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

Hi all.

I’m trying to disable/enable an area’s collision detection after receiving a specific signals.

The Game Over signal will disable the Area2D’s collision, and the New Game signal will enable the collision. The code below is from

func _on_BaseArea_area_entered(area):

func _on_HUD_play_game():
score = 0

I was thinking of using set_collision_mask_bit(), but I am having second thoughts.

:bust_in_silhouette: Reply From: kidscancode

If you’re using a CollisionShape2D in the area, you can use:

$CollisionShape2D.disabled = true

Hey, thanks!

System_Error | 2018-12-16 16:57

1 Like
:bust_in_silhouette: Reply From: rojekabc

And sometimes, if you want to change a range of objects in collision you may play with values of collision_mask or collision_layer.