#Changing sprite texture causes crash to desktop

8 messages · Page 1 of 1 (latest)

rocky pond
#

What is the correct way to change a sprites texture in code? this below crashes godot 3.5.3 to desktop:
At the top of the class i have:
[Export] public Sprite TestSprite;
which ive dragged a texture into.

then in _Ready:
public override void _Ready()
{
TestSprite.Texture = GD.Load<Texture>("res://Textures/Ranks/Rank0.png");
}
Run this and bang! a silent crash to desktop, no log or any output.

modest temple
#

when you run from console does it have any output?

rocky pond
#

do you mean to run the Godot editor from commnd line or somehow run my project from command line? im on a Mac by the way

modest temple
#

the editor

rocky pond
#

Hi, no there are no errors when run this way either, its a silent exit of the scene but not an exit of godot, just like you pressed the stop play button. It doesnt matter as I've just found the problem and its a design flaw in Godot if you ask me.

#

By having an [Export] next to the variable it implies you can drag the node into the varable in the inspector. It wouldnt let me drag a sprite node or texturerect into it but would let me drag an actual texture from the filesystem tab. it even filled it in and drew an icon of the texture. So basically I was trying to change the Texture attribute of a Texture in the file system not a node in the scene. So I changed the [Export] to a NodePath then in code get the node that way and i can now change the nodes texture. This can't be by design on Godot's part as its pure madness not to allow you to [Export] reference a sprite node or any other node for that matter execpt NodePath's. Not getting a good vibe from switching to Godot from Unity if you can't even do this properly.

modest temple
#

ouch

rocky pond
#

i now suspect this is what caused my earlier problem with Task functions.