+2 votes

Why doesn't disable the Collisionshape2d in code: "$CollisionShape2D.disabled=true". The collision shape is attached to a KinematicBody2. I did it exactly as shown in a tutorial, except that in tutorial Godot 3.0 was used.

in Projects by (28 points)

4 Answers

+1 vote

For some reason the following code doesnt work:

$CollisionShape2D.disabled = true

, however using the following works perfectly:

get_node("CollisionShape2D").disabled= true

you can also visualize the collisions from the Debug -> Visible Collision Shapes .. when it's disabled it turns to grey

I suggest you check in bugs list, and do a bug report if no one reported it earlier and not use $CollisionShape2D.disabled till it's solved

by (290 points)

Thank you for answer but it still doesn't work. It is strange that the collision shape does turn to grey but it is actually not disabled because can't pass through it.

hmm... very weird , do you mind uploading the project file to any storage cloud and share the link so I can check it in my side?

the link is private, cant open it

0 votes

I've encountered the same issue in Godot 3.1.2 and used layers as a workaround, but this seems to be fixed now in Godot 3.2 !

by (14 points)
+8 votes

Try this:

$CollisionShape2D.set_deferred("disabled", true)

Which waits until it's "safe" to actually disable the collision shape.

by (8,870 points)

I had the same issue with my project and calling

$CollisionShape2D.set_deferred("disabled", true)

resolved my enabling/disabling collision shape issue. Thanks

Thank's!!!! You really help me)

It really helps me!

Thank you for this,

The following code just doesn't work and it's the logical and common way to do this.

get_node("CollisionShape2D").disabled= true
$CollisionShape2D.disabled = true

can someone explain why this set_deferred thing works? The reason to disable it just because it's "safe" just doesn't make sense to me

0 votes

Even I am working on the same project. Instead of disabling CollisionShape2D I just deleted it.
It doesn't affect the scene but does the work.

by (30 points)
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.