@ready(): Node not found

Godot Version



Hi, I am new to GDScript and i am getting an error i dont understand. The script is for a enemy called “Slime”. According to my knowledge ‘ray_cast_left.is_colliding()’ is giving null value. I have checked the variable paths and it seems to be correct. The below is simple code for an entity to reverse direction if it encounters a wall. I followed a tutorial and it worked fine then. So i was surprised when i came back to it and i got an error.

extends Node2D

const SPEED = 60
var direction = 1
@onready var animated_sprite_2d = $AnimatedSprite2D
@onready var ray_cast_right = $RayCastRight
@onready var ray_cast_left = $RayCastLeft

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if ray_cast_left.is_colliding():
		direction = 1
		animated_sprite_2d.flip_h = false
	elif ray_cast_right.is_colliding():
		direction = -1
		animated_sprite_2d.flip_h = true
	position.x += direction * SPEED * delta

Here are some screenshots that might help:
Screenshot 2024-05-16 130205

Screenshot 2024-05-15 215605

The slime.gd script is assigned to a node called “Game”, which doesn’t look intentional. Make sure the Game node has the correct script assigned to it or no script at all, if it’s not supposed to have one.


This is what shows up when i view owners of the script. When i had created the script i had created it from the ‘Slime’ node, which according to my understanding inherits only from the ‘Slime’ node. So did the owner change or did it get edited somehow?

Also, how to change script assignment? :slightly_smiling_face:

So i deleted the old script entirely and copy-pasted the code into a new script that only inherits from the ‘Slime’ node and i am getting a similar error.

So there was a separate script file with the same code as slime.gd that i cannot find in the file path which means i can’t delete it. But if i delete the code in the file, i don’t get any error and the game runs. If anyone knows the reason for this, an explanation would be greatly appreciated.

try add

func _ready():
	await get_tree().physics_frame

in your code

1 Like

Thanks for the help @grulps

I added this to my code and it works. Thanks for the help @zdrmlpzdrmlp

In game.tscn the root node Game has the same script assigned to it. Select the Game and right click it, press “detach script”. You do not need to delete any scripts, or move any files around.

1 Like

Thanks @gertkeno i accidently attached the same script without realising it.