I'm setting up my pause menu and have 3 buttons: Inventory, Party, and Settings. These buttons are textures showing pixel art, which are set to highlight yellow when focused or hovered (all other textures left empty, including the normal, as that is in the Pausebar TextureRect. I would like the first button, Inventory, to be focused as soon as the pause menu launches. No matter where I put inventoryButton.get_focus(), it doesn't do it. In fact, no buttons seem to be able to focus. I would also like to have a Label (shown below as "Pause") to read out the names of the buttons as they are focused, but that's not working either.
Structure and scene look like this, where the buttons are the 3 trapezoids on the left (Pausebar is the node/scene in question here and what is pictured in the editor, but WorldUI is where it needs to work, editable children for PauseBar only for picture, normally turned off):
https://imgur.com/gallery/arVmB8D
Code looks like this (attached to WorldUI scene):
# Extensions
extends CanvasLayer
# Variables
onready var healthUI = $HealthUI
onready var pauseBar = $Pausebar
onready var tweenIn = $TweenIn
onready var tweenOut = $TweenOut
onready var inventoryButton = $Pausebar/PausebarSprite/InventoryButton
onready var partyButton = $Pausebar/PausebarSprite/PartyButton
onready var settingsButton = $Pausebar/PausebarSprite/SettingsButton
onready var pauseLabel = $Pausebar/PausebarSprite/PauseLabel
# Functions
func _ready():
healthUI.visible = true
pauseBar.visible = false
func _process(delta):
if get_tree().paused == true:
inventoryButton.grab_focus()
tweenIn.interpolate_property(pauseBar, "rect_position",
pauseBar.get_position(), Vector2(0, 0),
Tween.TRANS_SINE)
tweenIn.start()
else:
tweenOut.interpolate_property(pauseBar, "rect_position",
pauseBar.get_position(), Vector2(-320, 0),
Tween.TRANS_SINE)
tweenOut.start()
if inventoryButton.grab_focus():
pauseLabel.set_text("Inventory")
if partyButton.grab_focus():
pauseLabel.set_text("Party")
if settingsButton.grab_focus():
settingsButton.set_text("Settings")
func _on_TweenIn_tween_started(object, key):
pauseBar.visible = true
healthUI.visible = false
func _on_TweenOut_tween_completed(object, key):
pauseBar.visible = false
healthUI.visible = true
Everything else seems to work fine like the tweens, the visibilities, the functions in general...but for the life of me I cannot get the buttons to obtain focus and use the keyboard to cycle thru them. Using my mouse, I can hover over the buttons and the highlight and clicking side of things works fine (clicking doesn't show a different texture but leaves the button as yellow and shows up in Debugger>Misc). If I load the Pausebar scene on its own and click one of the buttons with my mouse, I can then scroll thru the buttons as intended with the ui_left, right, up, down buttons (yes I have set up the focus neighbors), but this does not work in any other scene, including WorldUI or a standard World level.
I have other buttons in my Title Screen scene, for instance, that work with getfocus() no problem just simply sitting in a Tween-connected function. For WorldUI, I have tried placing the getfocus() line in ready(), process() before and inside the if statement, and where it is now in the Tween-connected function.
Pls halp