0 votes

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"):
        collider.queue_free()
        print("Killed " + collider.name)

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):
https://www.youtube.com/watch?v=Y_2oiLjOx54&list=PLiUQR4U_J9efMalyhB1DtqywA_HPg-FrR&index=2

Godot version v3.2.3
in Engine by (12 points)

1 Answer

0 votes

make sure raycast var is storing the reference

var raycast = null
func _ready():
    raycast = $your_route
    print(raycast)
by (106 points)

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

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()

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.