0 votes

Hello community, I have a problem again.

var TextureReference = "[StreamTexture:1458]"

I have String variable called TextureReference that I want to set to Sprite, something like this:

$Sprite.texture = TextureReference

Any idea of how to accomplish that? I have tried:
str2var(TextureReference) but function str2var can't convert string into a object

in Engine by (14 points)

how do you get the string value? is it hard coded or do you str() an existing variable?

1 Answer

+4 votes

[StreamTexture:1458] cannot be used to get your texture, it is only a debug representation made by the print() or str() functions. If you got it from a file, this won't work either.

To obtain the texture you have to know its path:

var TextureReference = load("res://path/to/texture.png")

Or you may want to assign it from the inspector in the editor, by using export:

export(Texture) var TextureReference
by (27,902 points)
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.