Hi all. Just trying to turn an icon on or off and getting a strange error.

@onready var icon = $Panel/Icon

func _ready():
icon.visible = false

func set_attack():
icon.visible = true

Here's the relevant code. So the "icon.visible" is the problem. It works fine in the ready() func, but if I use the set_attack() func and the icon is already visible, it throws an error.

"Invalid set index 'visible' (on base: 'CompressedTexture2D') with value of type 'bool'."

Is this just happening because if the visible is on and you set it to on again it throws the error, or is there something else that is going on?

That doesn't seem to be the problem, because if I check if the icon is visible it throws the same error for that line instead. What is going on?

(Yes, the icon does exist, it's not null, I checked)

    What type of object is Panel/Icon?

    I recommend using static typing to make problems easier to diagnose.

    For example, if it's a Sprite2D:
    @onready var icon: Sprite2D = $Panel/Icon

    If you don't use static typing, a variable can change types, which can cause strange errors.

    CorvaNocta yes, your problem looks very simple.
    is $Panel/Icon a Button?

    the Button class has an icon property. you are trying to access or override an element of class because it has the same name as your variable. The strange thing is it should raise a warning. Are you looking at your warnings?

    Just change the name of icon for something else. And try to make the names of variables more unique.

    @onready var custom_icon = $Panel/Icon

      Jesusemora $Panel/Icon is not a button, it is just a Sprite2D

      This is the setup that I have. I am not sure why this would be giving these errors. It seems to be very odd.

      The code attacked to the Attack Slot:

      • xyz replied to this.

        CorvaNocta It seems to be very odd

        Not odd at all.
        In set_attack() you re-assign something else to the variable icon so after that it is no longer referencing $Panel/Icon you initially assigned to it.

          xyz ohhhhhh!!!!!!

          Ok I see the mistake now. I am setting the icon completely to something different, rather than setting the icon image as the image of the attack.

          Its all clear now! thanks!