RTS Minimap Controller

The RTS Minimap Controller provides a classic top-down minimap for your game. It handles rendering the map, displaying the camera's view frustum, and enabling click-to-move functionality.

Important: This component must be attached to a separate Camera, NOT your Main Camera. This "Minimap Camera" renders to a RenderTexture which is then displayed on your UI.

Features

  • Top-Down View: Renders an orthographic view of the battlefield.

  • Click-to-Move: Clicking on the minimap moves the Main Camera to that location instantly.

  • View Indicator: Draws a trapezoid or rectangle on the minimap showing exactly what the Main Camera sees.

  • Agent Rendering:

    • High Quality (Recommended): Supports GPU Instancer Pro to render thousands of actual unit meshes on the minimap efficiently.

    • Legacy Icons: Can render simple colored shapes (squares/circles) for units if preferred.

  • Static Background: Can capture a static screenshot of the terrain to save performance, rather than re-rendering the terrain every frame.

  • Fog of War Support: Hides units and areas that are not visible to the player.


Setup Guide

1. Create the Minimap Camera

  1. Create a new Camera in your scene (GameObject -> Camera).

  2. Name it MinimapCamera.

  3. Set Projection to Orthographic.

  4. Set Rotation to (90, 0, 0) (looking straight down).

  5. Remove the Audio Listener component.

2. Create the Render Texture

  1. In your Project window, right-click -> Create -> Render Texture.

  2. Name it MinimapRenderTexture.

  3. Set the size (e.g., 512x512 or 1024x1024).

  4. Assign this texture to the Target Texture slot of your MinimapCamera.

3. Setup the UI

  1. Create a Raw Image in your Canvas (UI -> Raw Image).

  2. Assign the MinimapRenderTexture to the Texture slot of the Raw Image.

  3. Place this Raw Image where you want the minimap to appear on screen (usually a corner).

4. Configure the Controller

  1. Add the RTSMinimapController component to your MinimapCamera.

  2. Main Camera Controller: Assign the RTSCameraController from your Main Camera.

  3. Minimap Texture: Assign the MinimapRenderTexture you created.

  4. Minimap UI Rect: Assign the RectTransform of your UI Raw Image.

  5. World Size: Set the width and height of your map (e.g., 500, 500).

  6. World Center: Set the center position of your map (usually 0, 0).


Rendering Agents on Minimap

To see your actual units (like tiny soldiers) on the minimap:

  1. Add a GPUI Camera component (from GPU Instancer Pro) to your MinimapCamera.

  2. That's it! The system will automatically render the instanced meshes on this camera too.

Option B: Simple Icons (Legacy)

To use colored squares or circles:

  1. Enable Show Agent Icons in the RTSMinimapController.

  2. Assign the Crowd Controller.

  3. Configure Icon Shape, Size, and Colors.

  4. Note: This uses a dedicated layer (default: 31) to render icons. Ensure your camera culling masks are set correctly.


Performance Optimization

Static Background

Rendering the entire terrain and environment twice (once for Main Camera, once for Minimap) is expensive.

  • Enable Use Static Background: The controller will take a "screenshot" of the map at startup and use that as a background texture.

  • Benefit: The Minimap Camera only needs to render moving units, saving massive GPU performance.

  • Refresh: You can trigger a refresh if the map changes dynamically.

Exclude Layers

Use the Exclude Layers mask to hide expensive effects like Particle Systems, High-Poly Trees, or Post-Processing volumes from the minimap camera.


Key Settings

View Indicator

  • Show View Indicator: Draws the camera's field of view.

  • Color/Material: Customize the look of the indicator.

  • Lock View Indicator Size: Useful if you want a fixed-size box instead of the actual frustum shape.

Player Target

  • Show Player Target: Displays an icon for your hero or base.

  • Player Target Icon: Assign a sprite (e.g., a green crosshair or hero face).

Fog of War

  • Fog Of War Provider: Assign your Fog of War component here.

  • Hide Non Player Factions: Automatically hides enemy units on the minimap if they are in the fog.

Last updated