0 votes

I need use variables as name of path to image.

Something like this, but this code isn't working:

var map = 1
var img = "res://Graphics/Maps/" + str (map) + ".jpg"
$"Map".texture.resource_path = img

How I can do this?
Thnaks a lot for answers!

in Engine by (263 points)
reshown by

2 Answers

+1 vote
Best answer

Call $"Map".texture = load(img) instead of $"Map".texture.resource_path = img changing the resource_path will not 'reload' the resource for you.

by (92 points)
selected by
0 votes
var map:int = 1
var img:String = "res://Graphics/Maps/"+str(map)+".jpg"
$Map.texture = preload(img)
by (215 points)

preload will not work if the path is not constant.

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.