hide/show button

Godot Version

4.2.2 stable

Question

I am having an odd problem. I have some code from a tutorial that shows a message when the player approaches the object. This uses a label to display the text and that works.

I wanted to change the label to a button, so I copied everything into new files and changed the label to a button. The problem is that I get an error when I try to run it.

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

I put the same reference that existed for the label in the code.

@onready var label = $Label
@onready var action_button = $ActionButton

then i show hide it based on a condition

action_button.show()
action_button.hide()

What am I doing wrong?

Thanks

Null means somethings missing, which looks like your button. Make sure you’ve got the right name in the onready.

1 Like

Yeah, it was a bit weird actually. The button was a child of the node that had the script, so it wasn’t like it didnt exist.

Anyways, i went a different direction and got what i wanted to happen working.

Thanks for the reply