system
February 4, 2017, 1:46am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
Robster
Old Version
Published before Godot 3 was released.
Hi all,
I have a TextureFrame called TypeL.
On the click of another button I want to change the image on this TextureFrame.
Here is my code:
get_node("TypeL").set_texture("res://textures/cpu.png")
When I run and click the button, this is the error:
Invalid type in function 'set_texture' in base 'TextureFrame'. Cannot convert argument 1 from String to Object.
I’ve had a look around. The docs basically just have this:
void set_texture ( Object texture )
I don’t know what I’m doing wrong. Any advice would be really appreciated. Thanks so much…
system
February 4, 2017, 1:53am
4
Reply From:
Robster
… annnnnd I answered it myself. There’s something about typing it out that helps sometimes.
Well, for others in the future I had to make the texture/png an object. Here’s how I did it:
#load the CPU image
image = load("res://textures/cpu.png")
#change the visuals
get_node("TypeL").set_texture(image)
Once the png file was an object I could then use that object to change the texture! Learning all the time. Hope that helps someone.
i was about to answer the load solution
mokalux | 2017-02-04 01:55
good answer, or you can just use …(which worked better for my application)
get_node("TypeL").set_texture(load("res://textures/cpu.png")
GodotBadger | 2020-05-30 00:21
system
August 8, 2019, 4:20pm
5
Reply From:
lastrodamo
Few month ago i search a solution for this error
On top of my script I declare this :
onready var material_body = preload("res://assets/drone/Peinture.material")
onready var graph2 = preload("res://assets/drone/images/graph2.png")
and in my button function :
func _on_button_graph2():
material_body.get("albedo_texture")
material_body.set("albedo_texture", graph2)
You can test a solution of my project in this link
In my case get_texture()
and set_texture()
not work