Invalid access to property or key 'timeout' on a base object of type 'null instance'.

Godot Version

4.7

Question

I’m trying to run the code below, but I’m getting the following error:

Invalid access to property or key ‘timeout’ on a base object of type ‘null instance’.

extends Sprite2D

var speed = 400
var angular_speed = PI

func _ready():
	var timer = get_node("Timer")
	timer.timeout.connect(_on_timer_timeout)

func _process(delta):
	rotation += angular_speed * delta
	var velocity = Vector2.UP.rotated(rotation) * speed
	position += velocity * delta

func _on_button_pressed():
	set_process(not is_processing())

func _on_timer_timeout():
	visible = not visible

Please, help me!!

Can you share a screenshot of the scene tree where this script is attached to?

It means that your timer variable is null, ie not actually referencing to a timer.

You create the timer variable and assign it here:

`var timer = get_node("Timer")`

This means there is no child node named “Timer”. And this node needs to be a child node of the Sprite2D node that you attach your script.

Here is the screenshot.

Thank you very much for your reply, but there is indeed a child node with the Timer. See the screenshot.

When you run the project, do you run node_2d scene or sprite_2d scene?

Try to drag the timer in while holding ctrl to make it an onready variable, then use that instead of get_node().

This is it.
The sprite_2d.tscn is the main scene, so you’re most likely running this scene when you hit Play, not the node_2d.tscn that you want to run.

node_2d scene

I’m pretty sure you are running sprite_2d scene. Can you double check this?
Can you also share a screenshot of sprite_2d scene?