How to use FileDialog to change texture?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kukuism21

I’m rather new godot. My project is to change the texture of a rectangle with a .png file from file dialog. I’m not so sure how to carry on with it and looked up as many tutorials and articles but found nothin that helps with my specific problem. Any suggestions? Thanks! This is the code I have so far. It’s kind of embarrassing to show but it’s what I have so far.

func _on_Upload_pressed():
$OpenFile.popup()

func _on_OpenFile_file_selected(path):
var profile = Image.new()
profile.open(path, 1)
$ColorRect/TextureRect

1 Like
:bust_in_silhouette: Reply From: Skyfrit

Here is the code:

var image = Image.new()
var image_texture = ImageTexture.new()
image.load(path)
image_texture.create_from_image(image)
$TextureRect.texture = image_texture