MiniMap Design


1 MiniMap Coordinate Calculation


The minimap navigation system is similar to another plugin, named Compact MiniMap. We make it as a blueprint-only module inside our framework and make it more easier to use.

Generally, we have mainly two ways to implement minimap logic.

  • Use a 3D camera to render the scene view into a render target texture every frame.

  • Use a fixed 2D map texture and convert a 3D location to a 2D translation in the widget.

As the first way has the higher cost of performance, we use the second way in our project. The idea of minimap can be explained by following picture.

minimapstruture


  • The parameters definition:

    • (W, L): The width and length of 3D level and we don’t need height for minimap.

    • (X, Y, Z): The center location of 3D level.

    • (X1, Y1, Z1): The location of an actor in the level.

    • (W2, L2): The width and length of 2D top view texture.

    • S2: The scale of 2D top view texture.

    • (X2, Y2): The 2D position corresponding the actor location (X1, Y1, Z1).

  • The formula of position calculation:

    • X2 = ((X1-X) / W) * W2 * S2

    • Y2 = ((Y1-Y) / L) * L2 * S2


2 Program Design


The minimap module in our project mainly contains following parts:

  • WB_MiniMap_USG: This is the minimap widget which contains all translation logic of minimap.

    • /Game/USGT/Framework/UI/MiniMap/WB_MiniMap_USG
  • WB_MiniMap_USG: This is the basic minimap item widget and you can derive this blueprint to create item widgets inside the minimap widget.

    • /Game/USGT/Framework/UI/MiniMap/WB_MiniMapItem_USG
  • MiniMapConfigProxy: Use to config the 3D level parameters of minimap.

    • /Game/USGT/Framework/UI/MiniMap/BP_MiniMapConfigProxy_USG
  • MiniMapActorProxy: The component to make its owner actor shown in the minimap widget.

    • /Game/USGT/Framework/UI/MiniMap/BP_MiniMapActorProxy_USG

2.1 WB_MiniMap_USG


This is the minimap widget which contains all translation logic of minimap. For example, the calculation to convert 3D location to 2d minimap position is given below.

worldtolocal


  • DefaultScale: Default scale of minimap texture.

  • MaxScale: Max scale of minimap.

  • OriginalSize: Original size of minimap.

  • ViewSize: View rect size of minimap.

  • SetLevelData: Update the level data, including level center location, level size, level top view texture and texture scale.

  • AdjustMiniMapSize: Adjust minimap size at runtime.

  • ConvertToMiniMapPos: Convert 3D location to 2D minimap position.

  • RefreshItem: Refresh minimap widget item data.

  • RemoveItem: Remove minimap widget item.

  • AddItem: Add minimap widget item.

  • FoldMiniMap: Fold minimap to a small view rect.

  • UnFoldMiniMap: Unfold the minimap to view the entire texture.

  • GetViewSize: Return the view size of minimap.

  • GetOriginalSize: Return the original size of minimap.

  • RefreshItemsWhenResized: Refresh all widget items when the minimap resized.

  • OnMiniMapSizeChanged: The event that will be called when the minimap size changed.


2.2 WB_MiniMapItem_USG


This is the basic minimap item widget and you can derive this blueprint to create item widgets inside the minimap widget.

Create a child widget blueprint of WB_MiniMapItem_USG and implement following interfaces.

  • OnItemAdd: Called when the widget item added in the minmap widget.

  • OnItemRemoved: Called when the widget item removed from the minimap widget.

  • OnMiniMapResized: Called when the minimap widget resized.

  • OnItemUpdated: Called when the logic data updated.

  • OnInitOwner: Called when the widget item was created by BP_MiniMapActorProxy_USG.

For example, we implemented the OnInitOwner interface for the player minimap item and modified the display when the player profile changed.

playeritem


The important properties are given below.

  • IsLocalPlayerItem: If true, this item will be used at the minimap center when folded. Generally, we use the locally controlled character as the minimap center point. This item will be always at the view rect center.

  • FollowParentScale: If true, this item will be scaled with the parent minimap widget.

  • IsStaticitem: If true, this item will not be updated after adding into minimap.

  • OwnerActor: The actor that this minimap item represented.

  • OwnerProxy: The owner minimap proxy component used to created this minimap item.


2.3 MiniMapConfigProxy


This proxy is the actor that should be put into the persistent level and config the parameters for the minimap.

minimapconfig


2.4 BP_MiniMapActorProxy_USG


In order to add minimap widget item for an actor easier, we add this minimap actor proxy component. With this component, the owner actor will be displayed in the minimap widget conveniently.

minimapproxy


  • WidgetClass: The widget class to represent the actor in the minimap.

  • NeedTickLocation: If true, the mark widget will be moved with the actor.

  • ApplyRotation: If true, the mark widget will be rotated with the actor.

  • ItemSize: The size of the widget.

  • ItemZOrder: The zorder of the widget. Use this to adjust the hierarchy of different minimap item widget.

  • ItemScaleFollowMap: If true, the widget will be scaled with the minimap.


3 Development Flow


See “The Usage of Mini Map”.