How do I prevent a button to close another UI?

So I trying to develop a UI navigation fully with a keyboard.

I can open a UI with the Esc button (let’s call it Player Menu), which shows an Inventory button. If I select the Inventory button, the Inventory menu will show up. (Both can be seen together, the player menu on the left side, and the inventory menu on the right side)

The problem is I use the Esc button to close any UI, so when I press Esc in the Inventory menu, both of Inventory menu and Player Menu will be closed. What I want to achieve is when I press the Esc button for the first time, it should close the Inventory menu first, then when I press Esc again it should close the Player Menu UI.

I actually finished implementing it, but I do think it’s not a good approach (It’s hard for me to read my own code lol). Do you have any suggestions?

Steps to success:

  • pick which order multiple windows should close in

  • when escape happens, iterate those windows in that desired order

  • as soon as you close one window, stop iterating.

1 Like

Oh wow never thought to save and iterate the window, thank you for the suggestion!

1 Like