I have problem with monitoring Area2D

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

There is a problem in my script that does let me change monitorable of key at first if but not letting me in elif. Ground is working properly and I know this can be the least polished way of doing it but I don’t have time to make it more polished so if it works I don’t care.

Here is the error : Attempt to call function ‘set_monitorable’ in base ‘null instance’ on a null instance.

Note : Key is an Area2D

var active = false

func _process(delta):

if active == false:

$Ground.scale = Vector2(0.05, 0.05)
$Key.set_monitorable(false)

elif active == true:

$Ground.scale = Vector2(1, 1)
$Key.set_monitorable(true)

I’m changing active var in another script

Also I don’t care if solution has monitoring if it is workin. Also I already tried disableing collision shape but same problem

:bust_in_silhouette: Reply From: timothybrentwood

Attempt to call function 'set_monitorable' in base 'null instance'means that _process(delta): was called $Key didn’t resolve to a valid value - like Godot wasn’t able to find a child node of the node that script is attached to named Key.

  1. Did you change the node path of the Key node in your scene tree and forget to change it in code?
  2. Are you calling queue_free() on Key anywhere in your code?
  3. Are you re-parenting Key at any point in your code?