Skip to main content

The Navigation Stack

One of the hardest things to code manually in UI is a robust "Back" button.

  • If I go Menu -> Settings -> Audio -> [Back] -> Audio? (No, Audio -> Settings).
  • What if I opened Settings from the Pause Menu vs Main Menu?

HookUI solves this with a classic Pushdown Automaton (Stack).

How it Works

  1. Push: When you navigate from Screen A to Screen B via a standard connection, Screen A is Pushed onto the stack.
    • Stack: [Screen A]
  2. Push Again: Navigate B -> C.
    • Stack: [Screen A, Screen B]
  3. Pop (Back): When you trigger the GoBack() function (or use the special Back button ID), the system Pops the top item.
    • It removes Screen B.
    • It navigates to Screen B (as the target).
    • Stack: [Screen A]

Logic Gates & "Back"

  • Portals: Portals generally DO push to the stack (they act like normal navigation).
  • "Back" Links: You don't need to draw a wire for the "Back" action if you use the standard back function. Drawing a wire manually creates a loop (Forward navigation), which adds to the stack instead of unwinding it.

Tip: Always prefer using the HookUIManager.GoBack() method or assign the special Back ID to your buttons for true "Return to previous" behavior.

Infinite Loops

Be careful not to create infinite stacks.

  • Menu -> Gameplay -> Menu -> Gameplay...
  • This will eventually crash memory if the user does it 1,000,000 times.
  • Solution: For major mode switches (like Menu to Gameplay), you often want to Clear the stack (future feature: Swap transition type).