Can't use set_collision_layer_bit in KinematicBody2D GDScript

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

I want to change collision mask’s and layers dynamicly with gdscript.A script attached to kinematic2d node.I cant use set_collision_layer_bit function in script.I’m getting an error

The method “set_collision_layer_bit” isn’t declared in the current class

How can i use set_collision_layer_bit function in kinematicbody2d ?

:bust_in_silhouette: Reply From: Sween123

set_collision_layer_bit() is a method of the class KinematicBody2D
Make sure the method is called from your KinematicBody2D.
The error The method “set_collision_layer_bit” isn’t declared in the current class means you are not calling this method from an object that is KinematicBody2D.

Thank you! I was changed node type from Node2D to KinematicBody2D.But the first line of the script still “extends Node2D”.I chanced it too.

Duhan BALCI | 2020-02-13 20:30