node is null???

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

the tree:
-KinematicBody: player
-Raycast: raydown

i have this code in player node for getting raydown:

onready var raydown = get_node("raydown")

it even suggested me the raydown option in the get_node() but it says it can’t find the node
(it could before and i did nothing with the code).

error:

E 0:00:01.155 get_node: (Node not found: “raydown” (relative to
“/root/Player”).) <Error C++> Condition “!node” is true. Returned:
__null <Source C++> scene/main/node.cpp:1371 @ get_node() <Trasování zásobníku>player.gd:23 @ _ready()

sorry for the language the last line of the error is in, i’m not abel to translate it to english
but it should be something like “stack trace”.

and:

Attempt to call function ‘get_collider’ in base ‘null instance’ on a null instance.

I really have no idea what i did wrong please help.

Why not just use $? Place $raydown.get_collider() in your script instead.

MTM828 | 2022-08-24 08:11

:bust_in_silhouette: Reply From: Inces

There is no collision in raycast at the moment of calling get_collider().dosomething

You have to make sure collider exists at this moment. Take a check

if get_collider() != null :

I can see You are expecting collision at the moment of ready(). Ready is called only once, so it You won’t detect any collision later with it. This function should be placed elsewhere. What do You want to do with this raycast and collider ?

it is called when pressing jump (spacebar)

and i tried that if you suggested but it gives the same error.

51m0n55 | 2022-08-24 12:09

Ah, sorry, it is whole raycast that is missing, not just collider.
The error indicates the number of line of code that provoked the error. It is also highlighted right after project crashes. Debug console shows remote version of editor, and You can check which instance caused this error, what functions led to this.
Possible reasons of this error would be :
-raycast is deleted or replaced somewhere before jumping
-there is no raycast named “raydown” as direct child of player
-there is another instance of player script in game, that doesn’t have raycast

Did You change anything in scene tree before it stopped working ?

Inces | 2022-08-24 12:39

i only changed scripts in other nodes but nothing else

51m0n55 | 2022-08-24 14:08

make sure these 3 things above don’t happen in your projects

Inces | 2022-08-24 21:17