UMG-Slate Compendium

repository·main·Indexed 21 days ago

https://github.com/yawlighthouse/umg-slate-compendium

A technical educational resource for Unreal Engine's UI systems, covering the low-level Slate C++ framework and the high-level UMG (Unreal Motion Graphics) wrapper. It provides guidance on event-based design for CPU performance, volatile widgets, in-world UI implementation via Widget Components and SMeshWidget, Slate memory management using Shared Pointers, and the Slate widget layout and invalidation processes.

Tokens
24.7K
Snippets
25
Records
95
Agent score
77%

What's inside umg-slate-compendium

  1. Overview of UMG-Slate Compendium

    main

    The UMG-Slate Compendium is a technical guide designed to teach the basics of Unreal Engine's UI frameworks: Slate and UMG (Unreal Motion Graphics). It provides a foundational understanding of how to work with these systems, covering performance considerations, input frameworks, focusing systems, and split-screen functionality.

    Prerequisites

    To use this compendium effectively, you should have a basic understanding of:

    • Blueprint and C++ in Unreal Engine.
    • Unreal Engine's Garbage Collection framework.
    • Unreal Engine's Gameplay Framework.
    • Sample Project: An Unreal Engine template project used in conjunction with this compendium can be found here.
    • FAQ: For questions regarding the document itself, refer to the FAQ Page.
  2. Find resources for Slate and UMG in Unreal Engine

    main
    The EXTERNAL_LINKS.md file serves as a directory for Epic Games documentation and community resources related to Slate and UMG. While the specific links are listed in the full document, users should refer to this file to find categorized information on official engine implementation and community-driven best practices.
  3. Configure Viewport Layout shapes

    main

    The default viewport layout is a rectangle defined by its X/Y size and X/Y position on the screen (using a 0-1 ratio for the center). This is initialized in the default UGameViewportClient constructor.

    To implement custom viewport shapes (non-rectangular), you must create a custom Game Layer Manager class capable of calculating the custom shape and applying it to the viewport widget.

  4. Understand the UTextLayoutWidget hierarchy

    main

    In Unreal Engine, UTextLayoutWidget serves as the base class for all core text widgets. When building text-based UIs, you will likely use one of the following specialized subclasses:

    • TextBlock: Standard text display.
    • RichTextBlock: Text support for rich text styling.
    • MultiLineEditableText: Editable text spanning multiple lines.
    • MultiLineEditableTextBox: An editable text box supporting multiple lines.
  5. Text Marshaller Type Hierarchy

    main

    The text marshalling system is built on a hierarchy of classes starting from a base interface. Use the appropriate subclass depending on whether you are handling plain text, rich text, or specialized log output.

    • ITextLayoutMarshaller: The base interface defining the contract for getting/setting raw text (FString) to/from a text layout (FTextLayout).
    • FBaseTextLayoutMarshaller: The primary base class intended for all custom marshaller implementations.

    Standard Implementations:

    • FPlainTextLayoutMarshaller: For simple, unformatted text.
    • FRichTextLayoutMarshaller: For text containing markup/styling.
    • FOutputLogTextLayoutMarshaller: Specifically for converting FOutputLogMessage objects into stylized lines for text layouts.
  6. How Split Screen and Game Layer Managers work

    main

    Split screen functionality in this framework relies on a Game Layer Manager. This manager is responsible for managing the viewport slate widget, determining which player is using a specific slate widget, and defining the shape/layout of that widget.

    By default, the engine instantiates the manager via UGameEngine or UEditorEngine. While you can attempt to use UGameViewportClient::SetGameLayerManager to provide your own, be aware of potential downstream effects from non-overridable engine code.

    When displaying widgets, you have two primary strategies:

    • Add to Viewport: The widget covers the entire game viewport, affecting all players. This is ideal for pause menus or full-screen overlays.
    • Add to Player Screen: The widget is restricted to a specific player's viewport. This is ideal for HUDs or player-specific UI elements in split-screen scenarios.
  7. How Text Decorators work in Rich Text Blocks

    main

    Text Decorators allow you to inject custom styling or interactive elements (like hyperlinks, inline images, or tooltips) dynamically into text blocks.

    Key Concepts:

    • Injection: Decorators are injected into the rich text layout marshaller and applied whenever text properties are set or changed.
    • Ordering: Decorators are applied in the order they are configured. If you want a decorator to act as a 'catch-all' for remaining text, place it last in your configuration list.
    • Configuration: You define which decorators to use by listing them in a data table, where each entry links to a decorator type and defines its behavior.
  8. How Rich Text Block painting works (OnPaint)

    main

    The OnPaint phase for a Rich Text Block follows this execution order to optimize CPU paths:

    1. Geometry Calculation: Calculates the text block's geometry and screen position using the cached text layout.
    2. Paint Data Building: Routes to FSlateTextBlockLayout::OnPaint, which then routes to FSlateTextLayout::OnPaint for actual drawing.
    3. Layout Recalculation: Recalculates the layout based on the prepared paint data, accounting for text wrapping.
    4. Invalidation: If the new layout size requires wrapping, the widget is invalidated to update its geometry size within the hierarchy.
  9. Understand the UMG class hierarchy

    main

    UMG (Unreal Motion Graphics) elements are UObjects tied to an Owning Player (a specific PlayerController). If no owning player is specified, it defaults to the first local player in the level.

    The hierarchy is as follows:

    • UVisual: The base class for elements in UMG Slots and Widgets.
    • UWidget: The base class for all Widgets. They create Slate Widgets and handle routing functionality from Blueprint/UObject classes to Slate (e.g., TextBlock, ScrollBox, Button).
    • UUserWidget: The base class for designing and animating UI and connecting it to game code. Unlike standard Actors, User Widgets do not require a root component, but they can inherit class functionality from C++ or abstract classes.
  10. Use Widget Components for world-space UI

    main

    Widget Components are UMeshComponents that render a User Widget as a procedural static mesh in the world using a render target.

    Key Constraints & Performance:

    • Dedicated Servers: They do not tick on dedicated servers. Consequently, collision based on the User Widget will not function on servers.
    • GPU Impact: Each component uses a render target updated on tick. High resolutions or high counts can significantly impact GPU memory.
    • Accessing the Widget: Use GetUserWidgetObject() to get the UUserWidget or GetSlateWidget() to get the underlying SWidget.
      • Note: GetUserWidgetObject is only valid from BeginPlay onwards; it cannot be used in an actor's construction script.

    Material Integration: When building materials for Widget Components, the following texture parameters are automatically supported:

    • SlateUI: Inputs the widget's Render Target.
    • TintColorAndOpacity: Inputs the component's TintColorAndOpacity property.
    • OpacityFromTexture: Inputs the component's OpacityFromTexture property.

    Player Ownership: By default, they use the first local player from the GameInstance. You can change this via SetOwnerPlayer(ULocalPlayer*).

  11. How Rich Text Block construction works

    main

    When the widget is constructed (e.g., during Blueprint recompilation in the editor), it caches designer-inputted data in the following order:

    1. Markup Parser: Caches the provided parser, or defaults to FDefaultRichTextMarkupParser.
    2. Text Marshaller: Caches the provided marshaller, or defaults to FRichTextLayoutMarshaller.
    3. Decorators: Caches optionally inputted decorators within the marshaller.
    4. Text Layout: Caches the FSlateTextBlockLayout and the marshaller within that layout.