TextureRect doesn't show textures

Godot Version

Godot v4.3 stable steam

Question

` Hi, I am very new to coding, game dev, Godot. I am trying to make a game with many levels and i have a stars system. I want to show how many stars on each level button’s top. I added a TextureRect to each level button(Button node). Everything works except the stars on top of buttons and this is my related code in level_selection script:

func _ready():
	for button in $VScrollBar/AnimalsLevels.get_children():
		if button is Button:
			button.connect("pressed", Callable(self, "_on_level_button_pressed").bind(button))
	for level_button in get_tree().get_nodes_in_group("animals_levels"):
		var level = int(level_button.name)
		var stars = Global.get_stars(level)
		var star_texture_path = "res://assets/star_" + str(stars) + ".png"
		level_button.get_node("StarDisplay").texture = load(star_texture_path)

My paths are correct, names are correct, Visible properties are on but i couldn’t get a result, please help`

I would run the game and open up the remote tab and see the state of the textureRect within your SceneTree.
Also are there any debugger notices? for example something like level_button.get_node("StarDisplay") is null.
Lastly, I would print out something inside your loop just to see if get_tree().get_nodes_in_group("animals_levels") actually returns an Array of level_buttons

1 Like