Course contentsShow
← Unreal Engine Game Development
Lesson 591 of 8808. User Interface and MetaSoundsFree lesson

Managing Complex UI Input Overlays

Learners will develop a manager class to handle input priority and focus stacking when multiple UI overlays are active simultaneously.

In this lesson, you will learn how to architect a UIInputManager to systematically handle input priority and focus stacking when multiple overlays—such as pause menus, inventory screens, and confirmation dialogs—are active simultaneously.

The Problem: Input Collisions

When your game has multiple layers of UI, simply toggling visibility isn't enough. If a player opens an inventory over a map, and both capture input, your game logic often suffers from "input bleed," where clicks pass through the background or multiple widgets fight for the same focus. To solve this, we implement a Focus Stack.

Architecting the Manager

The UIInputManager acts as a centralized controller. Instead of individual widgets handling their own focus, they register themselves with the manager when they open and unregister when they close.

The manager maintains a TArray<UUserWidget*> WidgetStack. When a new overlay appears, it is pushed to the top of the stack. The manager then enforces input priority by ensuring only the top-most widget in the stack can receive focus.

void UUIInputManager::PushWidget(UUserWidget* NewWidget)
{
    WidgetStack.Push(NewWidget);
    // Explicitly set focus to the new top-most widget
    NewWidget->SetFocus();
    // Disable input routing to underlying widgets
    UpdateInputRouting();
}

Implementing the Stack Logic

By using a TArray, you can easily manipulate the lifecycle of your UI. When a user presses "Escape" to close the topmost UI element, the manager handles the Pop() operation:

  1. Remove the top widget from the stack.
  2. Call RemoveFromParent() on the widget.
  3. Automatically set focus to the new top element of the WidgetStack.

This pattern prevents the common bug where closing a sub-menu leaves the game world "stuck" or fails to restore focus to the menu underneath. By centralizing this in a manager class, you keep your individual widgets decoupled; they only need to know how to notify the manager that their state has changed, rather than managing the complex focus state of the entire UI system.

Key Takeaway: Use a centralized TArray stack to manage your UI lifecycle, ensuring that focus is always explicitly routed to the top-most active overlay and restored to the previous layer upon closure.