I'm instancing button during runtime, and want to set their focus neighbors through code.

The return button here should focus itself when seeking its top neighbor.

for button in popup_box.get_children():
	if button.get_index() == 0:
		button.focus_neighbor_top = NodePath("%PopupReturnButton")

Godot keeps throwing me errors that the Node Path is invalid.

_get_focus_neighbor: Neighbor focus node path is invalid: '%PopupReturnButton'.

It does work when i type out the complete path like this: NodePath("../../../%PopupReturnButton")

Seems pointless to have a unique name thoguh, when you gotta type it out all the way anyway...
Is there a better way to set focus neighbors via script?

  • xyz replied to this.
  • Nevermind, i found a way myself. There's a built-function called get_path(), so you can just write it like this:

    NodePath(%ReturnButton.get_path())

    And that works without hitch~

    Nevermind, i found a way myself. There's a built-function called get_path(), so you can just write it like this:

    NodePath(%ReturnButton.get_path())

    And that works without hitch~

    xyz Boy, if i had a penny any time someone lazily points to the docs about an issue that has nothing to do with the question i asked. :^) Guys, if the answer was in the docs, nobody would have to ask questions to begin with. The docs do not help for specific issues like these.

    • xyz replied to this.

      Squiddy if the answer was in the docs, nobody would have to ask questions to begin with

      You'd be surprised how many people do precisely that.

      Squiddy if i had a penny any time someone lazily points to the docs about an issue that has nothing to do with the question i asked.

      I pointed you to the section in the docs that's exactly 100% relevant to your problem. I just didn't babysit you through it.