Godot: Invalid set index error

I'm trying to make UI for my game and making a button that changes its own focus neighbour when pressed:

$SettingsButton.focus_neighbour_left =$ItemGrid/Slot2

But when I press the button, it gives this error:

Invalid set index 'focus_neighbour_left' (on base: 'TextureButton') with value of type 'TextureButton'.

I tried searching around but I don't know what this error is telling me or how to fix it.

To be clear, the scene tree isn't changing and Slot2 is a TextureButton.

1 Answer

Thearot figured it out, I just needed to change

$ItemGrid/Slot2 to $ItemGrid/Slot2.get_path()

• By the way Godot has NodePath literals. For example @"ItemGrid/Slot2". However, written like that it would be relative, which is not good for passing around. Because of that, I would go with \$ItemGrid/Slot2.get_path() which gives you an absolute one. Oct 18, 2021 at 14:09
• I realised the solution I found is actually incorrect and I didn't do proper testing before posting my answer, but your answer works perfectly! Thanks @Theraot! Oct 18, 2021 at 18:46
• Reminder: you can accept your own answer. Oct 20, 2021 at 18:42