0 votes
$Sprite.texture = "res://Img/black.png"

returns this error
Invalid set index 'texture' (on base: 'Sprite') with value of type 'String'.

I thought this was very easy, but I have not found a way to do it

in Engine by (93 points)

1 Answer

+7 votes
Best answer

You need to wrap that image reference in a load call. So, this...

$Sprite.texture = load("res://Img/black.png")
by (21,698 points)
selected by

Two questions

1) if i had a bunch of sprites say 1-5 and had a rng pick one how would i load that one. If i had it set up like var 1 = sprite path ect and then did $Sprite.texture = load (1) would that work?

2)how do you find the correct path?

Thank For your help.

question 1:
in theory, yes it will.

question 2:
go to the picture in the godot editor, right click it and press copy path.
happy coding!

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 Frequently asked questions and 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 [email protected] with your username.