so i have some code, i realized there's a button.icon property which changes the texture, but i can't find a way to set the image i want to it through code

extends Control

func _ready():
	var button = Button.new()
	button.text = "Click me"
	button.icon = "res://yea.png"

doesn't show any errors while scripting but when i load the game it crashes and gives me the error

" Invalid set index 'icon' (on base: 'Button') with value of type 'String'. "

maybe try "res://yea.png.stex" or such(check in the .import folder) instead of "res://yea.png"? Or alternatively make sure that there is a yea.png.import file properly generated next to the yea.png in your file hierarchy.

@Megalomaniak Same error, it's ok i'll just, find another way around

derp yeah, good catch. Need to use ResourceLoader to load the texture there. So something like:

    extends Control
    func _ready():
        var button = Button.new()
        button.text = "Click me"
        button.icon = ResourceLoader.load("res://yea.png")
2 years later