Disabling collision shape 2D frees it from memory

Godot Version

4.5

Question

Disabling collision shape 2D frees it from memory, resulting in the error “Cannot call method ‘set_deferred’ on a previously freed instance.” when trying to enable it back

I have a static body 2D with two collision shape 2D as children.

image

I also have in this scene a button that I use for drag purposes.
On button down it disables collisions of the two collision shapes I use, and on button up it tries to reenable them but that’s when the game crashes with the error.

The whole static body and the collision shapes have disappeared from the Distant tree tab, and the collision shapes references appear as null

Here is the code

func _on_button_drag_button_up() → void:
enableCollision()

func _on_button_drag_button_down() → void:
disableCollision()

func disableCollision():
bounce_collision.set_deferred(‘disabled’, true)
bounce_collision_2.set_deferred(‘disabled’, true)

func enableCollision():
bounce_collision.set_deferred(‘disabled’, false) #The line it breaks
bounce_collision_2.set_deferred(‘disabled’, false)

Thank you everyone for your help

Couldn’t reproduce the issue…
Could you upload a minimal project zip?
Nvm, doesn’t seem like u can upload a zip

You are probably deleting the Bounce or it’s children elsewhere. Do you have queue_free anywhere in your code, even other scripts?