my game crashes and has this error Invalid access to property or key 'local_position' on a base object of type 'null instance'.

left click input is a place holder till I make a timer thing

Question

Ask your question here! Try to give as many detailss possible.

I’m trying to make a spawner for my enemy(left click input is a place holder until I can figure out

how to make a timer thing

extends Marker2D

const circle = preload("res://scenes/circle.tscn")

@onready var muzzle: Marker2D = $Marker2D
 
 
func _process(delta: float) -> void:
	if Input.is_action_just_pressed("Left click"):
		var circle_instance = circle.instantiate()
		get_tree().root.add_child(circle_instance)
		circle_instance.local_position = muzzle.local_position
		circle_instance.rotation = rotation

It looks like muzzle is the variable that has null instead of the Marker2D node. You should double check the node path for it.

2 Likes

What is the error? Is your target null? Typically you should not use back paths (ones starting with $"../) You may have better luck using an @export variable instead of @onready

1 Like

Please, view error message.