12

Hi all, I'm new to Godot and recently returned to my project that I have started last year. I've been trying to create a reusable button and use it in my GUI scenes. I created a separate scene round_button.tscn which has the following structure:

Control
 └─ RoundTextureButton
     └─ CenterContainer
        └─ IconTextureRect

RoundTextureButton is a TextureButton that reacts to mouse hover and IconTextureRect is a TextureRect that is meant to be an icon with texture set as an AtlasTexture. I made the following script that is attached to Control:

extends Control
class_name RoundButton

enum IconID { play, pause, back, forward, … }

const ICON_REGIONS =  [
	Vector2i(64, 0),
	Vector2i(64, 16),
	…]

@export var icon_id: IconID = IconID.play
@onready var icon_rect: TextureRect = $RoundTextureButton/CenterContainer/IconTextureRect

func _ready() -> void:
	icon_rect.texture.region = Rect2(ICON_REGIONS[icon_id], Vector2i(16, 16))

This creates a dropdown in Godot GUI which allows me to comfortably set the type of a button. It works as expected when I run the button scene.

Then I Instantiate Child Scene… in my menu scene menu.tscn to add a few buttons to my game menu. One button works fine, but when I add two or more, they all have the same icon, the last button that I added and set. What am I missing here with sharing attributes? I read that exported arrays are shared by all instances because the variables are really pointers to some memory location, but my icon_id is an enum value. To test this I have put a print statement in _ready() and it seems like the buttons have distinct values, but the icons are still shared by all of them.

you are viewing a single comment's thread
view the rest of the comments
[-] polotype@lemmy.ml 4 points 1 week ago

I'm guessing it something about the texture you use not being a unique resource. You mighwant to learn about "make unique" and the like, but i'm not sure.

[-] blamster19@programming.dev 4 points 1 week ago

It was "Local to Scene" tick in the AtlasTexture's Resource group that had to be checked to make the atlas unique to an instance. Thank you.

this post was submitted on 01 Aug 2026
12 points (92.9% liked)

Godot

7826 readers
28 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 3 years ago
MODERATORS