Trying to change textureRect's Texture in code for card program, but it keeps trying to load StreamTexture

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DJ_Fail87

The resource paths are correct, I’ve checked several times, and they are PNGs, not stex files. The other card deck works correctly, but this one doesn’t, by which I mean that no texture shows up.

func _generate_weird(count):
$VBox/WeirdDeck/CenterContainer/GridContainer.columns = count
for i in count:
	var cardn = DiceRoller.roll_dice(100,1)
	var card = $VBox/WeirdDeck/CenterContainer/GridContainer.get_child(i)
	var card_texture = load(weird_deck[cardn])
	card.expand = true
	card.texture = card_texture
	card.rect_size = Vector2(card.texture.get_size()) * Vector2(.35,.35)

Edit: clarified what not working correctly meant

Godot doesn’t load PNGs directly. Instead they are imported as StreamTextures in the .import folder. What do you mean that it doesn’t work correctly?

exuin | 2022-03-06 18:11

That no image loads for the texture.

The card.texture = card_texture works for the other deck, but not this one.

DJ_Fail87 | 2022-03-06 18:16

what is weird_deck?

exuin | 2022-03-06 18:56

Assuming your UI and nodes are properly setup (i.e they have non-zero size, are not transparent etc), if no texture shows up, it means card.texture was left to null.
Which means either:

  • card_texture is null. Which means load(weird_deck[cardn]) returned null. Which means weird_deck[cardn] contains an invalid texture path, or not even a path at all.

  • Or, card.texture does not contain a texture, but something else that the TextureRect is not compatible with. If it is an Image for example, images are not textures. Sometimes Godot silently converts to null in those cases. But unless you manually changed the import type of your PNG, Godot imports it as StreamTexture by default so it seems unlikely.

  • Or maybe there is an error somewhere and you should check your logs. Brings back to load failing: this doesnt stop the game if it fails, but it might log an error that you should check.

  • Or maybe that whole code doesn’t run at all, not sure what more to tell from the code you posted.

So you should verify this stuff by debugging, printing, trace back to the source of your data.

Zylann | 2022-03-07 13:37