Conforming Player and Widget Cursors

October 28, 2020

·

Cursory

·

The Slate framework for Unreal Engine 4 is responsible for deciding which cursor is shown on the screen at any given time. It makes this decision by looking at a few different sources. Cursory manages one cursor, and it makes it easy for you to ensure that all sources point to that cursor.

Cursor Sources and Priority

The Slate framework looks at two sources when deciding which cursor to show: player controllers and widgets. To make things more complicated, player controllers and widgets maintain their own cursors. Typically, cursor selection follows this priority:

  1. If the player controller's ShowMouseCursor property is false, no cursor is shown. Otherwise...
  2. If the cursor is captured by a widget, the capturing widget's cursor is shown.
  3. If the cursor is hovering over a widget, the hovering widget's cursor is shown.
  4. If the cursor is over the viewport, the player controller's cursor is shown.

This can introduce quite a bit of confusion, in terms of where a cursor is coming from at any point in time. Cursory simplifies this by maintaining one cursor and ensuring that all other sources point to that cursor. We recommend conforming all player controllers and widgets using the methods provided below, to ensure maximum consistency.

Conforming Player Controllers

To conform a player controller, simply add the CursoryConformerComponent to the controller from Blueprints or C++.

Conformed player controller

The player controller cursor will automatically be synchronized with Cursory.

If you ever want to stop syncing a player controller to Cursory, you can simply Deactivate() the Conformer component. When you want to resume synchronization, just Activate().

Conforming Widgets

To conform a widget, call one of the conformance functions provided in the CursoryFunctionLibrary:

  • ConformWidgetToCursory - Synchronizes a UWidget (such as a button)
  • ConformWidgetsToCursory - Synchronizes a list of UWidgets
  • ConformWidgetToCursory (Recursive) - Sychronizes a UUserWidget (i.e. a WidgetBlueprint) and all of its children (prefer this option in most cases)

Conformed widget

Using any of these methods will synchronize your widgets with Cursory.

If you ever want to stop syncing a widget to Cursory, use the SetCursor() or ResetCursor() functions. To resume synchronization, use one of the methods above.



© 2021 Mustafa Moiz.