Can't find (existing) node and the instance is supposedly null. What am I missing??

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

I’ve been into programming for around a month now and choose godot as my first engine. At the moment I’m just learning/practicing with random tutuorials I find on the internet. I’ve had a few issues already, but I fixed those with logic combined with trial and error. But I have finally hit a problem I can’t solve.

The raycast which in the code I named “raycast” is supposed to be an onready var variant of RayCastCombat. While this worked for a while after it was written, at some point it just stopped working properly and causes a breakpoint.
The error text reads: Attempt to call function ‘is_colliding’ in base ‘null instance’ on a null instance.

onready var raycast = $"/root/World/Player/Controller/Head/Camera1/RayCastCombat"

func check_collision():
if raycast.is_colliding():
	var collider = raycast.get_collider()
	if collider.is_in_group("Enemies"):
		print("Killed " +

I tried using different node paths, but no matter if I used ‘$’ or ‘…/’, the problem is the same.

I’ve watched this tutorial on raycast (The tutorial source code is in the comments):

:bust_in_silhouette: Reply From: lofi

make sure raycast var is storing the reference

var raycast = null
func _ready():
    raycast = $your_route


It doesn’t work.

I also tried using it in my function, but now I get a different error:
“Invalid call. Nonexistent function ‘is_colliding’ in base ‘Nil’.”

I’m sure the node path is correct, but it doesn’t seem to recognize it and is therefore referring to null as Nil

Shadey01 | 2021-03-27 19:11

if raycast return null or nil it’s because it isnt storing the path, try instead of $path the get_node() it has autocompletion so maybe from there you could get the path.

if it doesnt work, from the main parent node try print_tree() or print_tree_pretty()

lofi | 2021-04-01 08:33