Skip to main content
Flow Core Documentation
Menu

Stack

Composing Logic with Stacks

Layer temporary modes and restore the previous mode with explicit push and pop lifecycle.

Audience
Gameplay and UI developers
Time
12 minutes
Requires
A last-in, first-out mode requirement
Modules
Stack
On this page

Use Stack when a temporary layer covers the current mode and the previous mode must resume after the layer is removed. Typical uses include nested menus, dialogue input, inspect mode, and tutorial overlays.

Mental model

Stack Root owns the ordered collection. Stack Layer is the item that can be pushed.

Only the top layer receives Update. A layer below it remains paused until every layer above it is popped.

Lifecycle outputMeaning
PushThe layer is added to the stack.
ResumeThe layer becomes the active top layer.
UpdateThe current top layer receives its configured update.
PauseThe layer stops being top.
PopThe layer is removed.

Build a UI stack

  1. Add a Stack Root and name it UiStack.
  2. Configure the root’s Update Interrupt policy.
  3. Add Stack Layers named Gameplay, PauseMenu, and Options, then configure each layer’s update interval.
  4. Set every layer’s Root Name to UiStack.
  5. Put show or enable work in Resume.
  6. Put hide or disable work in Pause.
  7. Put one-time setup and cleanup in Push and Pop.
  8. Enable unique layers when a screen must not be pushed twice.

Select the PauseMenu layer and inspect its Pause and Resume outputs. Follow Resume to the Action that restores the menu. Use the Flow Inspector to read the layer’s own lifecycle Instruction sections. Single Focus keeps the active entry and its parent section open. Choose Continuous to compare two lifecycle entries side by side in the same list of sections. See Node Inspector & Entry Editing.

The UiStack Inspector shows Options as the active layer, Stack Tutorial Owner as the layer owner, and a stack size of 3.

Pushing Gameplay, PauseMenu and then Options leaves three layers on UiStack. Active Layer identifies the top layer.

Expected runtime order:

Gameplay active
Push PauseMenu -> Gameplay pauses, PauseMenu resumes
Push Options   -> PauseMenu pauses, Options resumes
Pop Options    -> Options exits, PauseMenu resumes
Pop PauseMenu  -> PauseMenu exits, Gameplay resumes

When Stack is not the owner

Do not use Stack when two systems should update concurrently. Independent movement and upper-body state families are better expressed as separate FSM groups or processes. Do not use Stack merely because several nodes form a list.

Root and layer names are runtime relationships. Keep them stable and add comments around cross-process pushes so target ownership remains visible.

Common mistakes

SymptomCheck
A layer never joins the stackIts Root Name must match the Stack Root title.
Lower layers keep updatingConfirm their work is connected to the layer Update lifecycle rather than a separate Trigger.
The same menu appears twiceEnable unique layers where duplicates are invalid.
Push waits unexpectedlyCheck the root’s Update interruption mode and active Update work.
Two concurrent systems block each otherThey should not share one last-in, first-out stack.