How-To: Show a Widget on a UI Layer
Goal: use the CommonUI foundation in CrimsonCommon to push an activatable widget onto a named layer of the primary game layout - the HUD/menu stack that replaces the CommonGame plugin.
UCrimsonGameUIPolicy set up with your UCrimsonPrimaryGameLayout subclass (the layout Blueprint that owns your layer containers).1. Register your layers
In your primary-layout widget, register each layer container against a UI.Layer.* tag (e.g. UI.Layer.Game, UI.Layer.GameMenu, UI.Layer.Menu, UI.Layer.Modal). The layout calls RegisterLayer(LayerTag, Container) for each UCommonActivatableWidgetContainerBase it owns. Layer tags are project-defined - CrimsonCommon doesn't hardcode them.
2. Push a widget to a layer
From anywhere with a player, push an activatable widget class onto a layer. The widget is created, activated, and added to that layer's stack.
Images/CrimsonCommon/howto-ui-push.pngFindAndRemoveWidgetFromLayer).3. (Optional) Make a layer extensible
To let other plugins inject widgets into a slot without you referencing them, use the UI Extension system. Register an extension point (a named slot) in the host widget, and have contributors register an extension widget against the same tag. CrimsonCommon brokers the match.
// Contributor side - inject a widget into a named slot, no host reference:UGameInstance::GetSubsystem<UCrimsonUIExtensionSubsystem>(GI)->RegisterExtensionAsWidget(Tag_UI_Extension_HUD_Bottom, MyWidgetClass, /*Priority*/ 0);
UCrimsonUIExtensionSubsystem), returning handles you keep to unregister.See also
- Concept: Modular Actors & Player Layer - where the UI policy and local player fit
- API Reference -
UCrimsonPrimaryGameLayout,UCrimsonUIExtensionSubsystem