0 votes

I am trying to run a script to change the texture of one of my textured buttons (right now just in the ready function but eventually on signals); however, I keep getting the error message

Attempt to call function 'setnormaltexture' in base 'null instance' on a null instance.

Based on making small changes it seems like my code is not recognizing my Button1 , but I am not sure why.

extends CenterContainer


func _ready():
    $Button1.set_normal_texture("res://Images/PeiceTile.png")

My nodes are a CenterContainer which containsHBoxContainer which contains Button1, Button2,..., Button 7.

Thank you in advance to anyone who is able to help me!

in Engine by (15 points)

1 Answer

+1 vote
Best answer

Try with $HBoxContainer/Button1 (or whatever your hboxcontainer name is). Nodes are accessed by path, not just by name.

by (27,900 points)
selected by

Thank you so much! I tried $HBoxCotainer.Button1 earlier but obviously I had the syntax wrong!

Also note to anyone else who looks at this in the future, i also needed to preload the texture to get this to work so my final code is

extends CenterContainer


func _ready():
    var PeiceTile = load("res://Images/PeiceTile.png")
    $HBoxContainer/Button1.set_normal_texture(PeiceTile)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.