The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hello everyone!

So,i've been struggling to change the sprites texture.What i'm trying to achieve is change the sprite image of a node using a resource path(e.g."res://Sprites/crop0.png") that is inside of an array.

The array has 4 resources paths all of them are the same as the example.
This is what i wrote: sprite.texture = crop[1]
But if i try to run the game i get an error:Invalid set index 'texture' (on base: 'Sprite') with value of type 'String'.

I also tried to change the texture_normal of a texturebutton and it doesn't work as well.Same error.I didn't make any typo at the path...

And that was it... Let me know if you know how to fix this or even an idea please.
Have a good day.

in Engine by (108 points)

3 Answers

+2 votes
Best answer

Hi I am a beginner in godot, too. But I guess the problem is you are trying to put a 'String' to that sprite's texture. String is not a texture as error mentioned (" with value of type 'String'. ") :) you should 'load' that texture :)

You can do it like that: sprite.texture = load(crop[1])

by (67 points)
selected by
+2 votes

sprite.texture expects a Texture
crop[1] gives you a String
what you need to do is to load that resource:
sprite.texture = load(crop[1])

by (42 points)
+2 votes

Your array crop[1] is String not Texture
All you need is load()
sprite.texture = load(crop[1])

You can use AnimatedSprite Node to get the same result You can watch the tutorial from Here

by (47 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 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.