Disable or enable a node in a Script C#

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

So I am trying to make a script that disables a collision box so " Node " for the player and enables another one so that they could crouch or crawl. For a 2D game.

For example a godot Script

func _physics_process(delta):
var col = get_node(“CameraPosition/Area2D/CollisionShape2D”)

For C# disabled does not exist, so the question is how do I disable the Node ?
Example code
2 Colliders : StandingCollison" Which is defaulted to true as in enabled and " CrouchCollision" which is disabled “False”

if (Input.IsActionPressed(“ui_down”) && (on_ground == true)){
var node = GetNode(“StandingCollison”);

As far as I have searched I cannot figure this out, and throughout multiple forums that Godot has provided this has not been listed for C#.

The Colliders should Get disabled when A button is pressed and another one gets enabled, and when its pressed again it would then do the reverse, I want to know how to disable it…

:bust_in_silhouette: Reply From: betauer

The CollisionShape2D class has a Disabled field. What are you missing is to specify the class in the GetNode() in this way:

var node = GetNode<CollisionShape2D>("StandingCollison");
node.Disabled = false;

If you just call to the GetNode without type, the node variable will have Node as type, and this type doesn’t have the Disabled flag.