• Godot HelpProgramming
  • Invalid get index 'disabled' (on base 'null instance'). On line that doesn't have 'disabled'

I copied and pasted this line of code that the error was appearing on and no sign of the word 'disabled'. There is however lower down in the code a timer signal connected function that uses it. I cannot work out what is wrong because I cannot find anywere through breakpoints that the link button I was controlling with the 'disabled' property doesn't have an instance attatched. I even looked in the remote scene debugger and no sign of it going wrong.

extends CanvasLayer

signal restart

enum State {SETUP, PLAYING, MENU}

onready var credits_btn = $Menu/CreditsButton

func _ready():
	set_process(false)
	show_mode(State.SETUP)

func _process(delta):
	# Use the flying buttons to restart the game if the menu is active and the accidental-click period has ended
	if Input.is_action_just_released("fly") and $Menu.visible and not $Menu/CenterContainer/MenuBackground/CenterContainer/VBoxContainer/CenterContainer/TextureButton.disabled:
		_on_TextureButton_pressed()

func set_score_label(score):
	# Set both of the score labels in step
	$ScoreLabel.text = str(score)
	$Menu/CenterContainer/MenuBackground/CenterContainer/VBoxContainer/CurrentScore/ScoreLabel.text = str(score)

func set_previous_best(score):
	$Menu/CenterContainer/MenuBackground/CenterContainer/VBoxContainer/PreviousBest/ScoreLabel.text = str(score)

func show_mode(mode):
	match mode:
		State.SETUP:
			$ScoreLabel.hide()
			$Menu.hide()
		State.PLAYING:
			$ScoreLabel.show()
			$Menu.hide()
		State.MENU:
			$ScoreLabel.hide()
			$Menu.modulate.a = 0
			$Menu.show()
			credits_btn.disabled = true
			$AllowClIck.start()
			$AnimationPlayer.play("fade_in_menu")

func _on_TextureButton_pressed():
	emit_signal("restart")


func _on_Dialog_dialog_ended():
	show_mode(State.PLAYING)


func _on_Player_death():
	show_mode(State.MENU)


func _on_CreditsButton_pressed():
	var credits_window_scene = load("res://Scenes/HUD/Credits.tscn")
	var id = credits_window_scene.instance()
	add_child(id)
	id.connect("closed", self, "_on_CreditsWindow_closed")
	set_process(false)

func _on_CreditsWindow_closed():
	set_process(true)


func _on_AllowClIck_timeout():
	set_process(true)
	credits_btn.disabled = false

Which line is Godot saying is the issue with the disabled property?

Sometimes Godot can incorrectly report which line was causing the issue, but generally the issue is fairly close nearby to the line that the error is reported. I've found that generally the line is different than the error if the error occurs within a condition or loop.

Just looking at the code, I think it might be line 38 that is the issue, as perhaps the credits_btn variable is not set to the node when its called.

a year later