Minimap System
Render texture minimap with player icon, enemy blips, objective markers, and zoom control.
No APIs that Unity 6.0 to 6.6 made obsolete or removed. How this is checked
What it adds to your GameObject
A MonoBehaviour component: attach it to a GameObject. This is the Inspector you get, read from the source: 10 serialized fields with their defaults.
When to use it
Essential for open-world RPGs, RTS games, and exploration games where players need spatial awareness. Great for showing enemy positions, quest objectives, and points of interest. Pair with Top-Down Camera for a cohesive RTS control scheme.
Setup
- Create a secondary Camera set to Orthographic, looking down (rotation 90,0,0)
- Set it to render to a RenderTexture (create one: 256x256)
- Display the RenderTexture in a RawImage UI element (circular mask optional)
- Attach MinimapSystem, assign the camera and player transform
- Register icons: MinimapSystem.RegisterIcon(enemy.transform, Color.red)
- Unregister on destroy: MinimapSystem.UnregisterIcon(transform)
- Create a 'Minimap' layer and set camera culling to only show minimap objects
Features
- Render texture-based minimap with dedicated orthographic camera
- Automatic player following with optional rotation-match
- Dynamic icon registration and unregistration for any tracked object
- Configurable zoom in/out with smooth interpolation
- Automatic cleanup of icons for destroyed objects
- Singleton pattern for easy global access from any script
Inspector fields
Every field Minimap System exposes in the Inspector, with the default it starts at.
| Field | Type | Default | Group |
|---|---|---|---|
Minimap CameraminimapCamera | Camera | None | Camera |
Player TransformplayerTransform | Transform | None | Camera |
Heightheight | float | 40 | Follow |
Rotate With PlayerrotateWithPlayer | bool | false | Follow |
Default ZoomdefaultZoom | float | 30 | Zoom |
Min ZoomminZoom | float | 15 | Zoom |
Max ZoommaxZoom | float | 60 | Zoom |
Zoom SpeedzoomSpeed | float | 5 | Zoom |
Icon PrefabiconPrefab | GameObject | None | Icons |
Icon ScaleiconScale | float | 1 | Icons |
Public API
What other scripts can call on MinimapSystem.
| Member | Returns | Description |
|---|---|---|
static RegisterIcon(Transform target, Color color, float scale = 1f) | void | Register a transform to show on the minimap. |
static UnregisterIcon(Transform target) | void | Remove a tracked icon from the minimap. |
ZoomIn() | void | Zoom in the minimap. |
ZoomOut() | void | Zoom out the minimap. |
Initialize(Transform trackedTarget, Color color, float scale) | void | |
static Instance property | MinimapSystem |
Common mistakes
You must create a dedicated 'Minimap' layer and set the minimap camera to only render that layer — otherwise it will render the full scene. The minimap camera needs a RenderTexture assigned as its Target Texture, and a RawImage UI element must display that texture. Icon prefabs need a Renderer component for the color to apply; SpriteRenderers work too.
Source code
MinimapSystem.cs, 177 lines, MIT licensed. Paste it into a new C# file of the same name.
using UnityEngine;
using System.Collections.Generic;
/// <summary>
/// Render texture minimap. Requires a secondary orthographic camera
/// rendered to a RenderTexture displayed in a RawImage UI element.
/// </summary>
public class MinimapSystem : MonoBehaviour
{
public static MinimapSystem Instance { get; private set; }
[Header("Camera")]
[SerializeField] private Camera minimapCamera;
[SerializeField] private Transform playerTransform;
[Header("Follow")]
[SerializeField] private float height = 40f;
[SerializeField] private bool rotateWithPlayer = false;
[Header("Zoom")]
[SerializeField] private float defaultZoom = 30f;
[SerializeField] private float minZoom = 15f;
[SerializeField] private float maxZoom = 60f;
[SerializeField] private float zoomSpeed = 5f;
[Header("Icons")]
[SerializeField] private GameObject iconPrefab;
[SerializeField] private float iconScale = 1f;
private float currentZoom;
private Dictionary<Transform, MinimapIcon> trackedIcons = new Dictionary<Transform, MinimapIcon>();
private void Awake()
{
if (Instance == null)
Instance = this;
else
{
Destroy(gameObject);
return;
}
currentZoom = defaultZoom;
if (minimapCamera != null)
minimapCamera.orthographicSize = currentZoom;
}
private void LateUpdate()
{
if (minimapCamera == null || playerTransform == null) return;
// Follow player
Vector3 camPos = playerTransform.position;
camPos.y = playerTransform.position.y + height;
minimapCamera.transform.position = camPos;
// Rotation
if (rotateWithPlayer)
{
minimapCamera.transform.rotation = Quaternion.Euler(
90f, playerTransform.eulerAngles.y, 0f
);
}
else
{
minimapCamera.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
}
// Update zoom
minimapCamera.orthographicSize = Mathf.Lerp(
minimapCamera.orthographicSize,
currentZoom,
Time.deltaTime * 5f
);
// Update tracked icons
CleanupDestroyedIcons();
}
/// <summary>
/// Register a transform to show on the minimap.
/// </summary>
public static void RegisterIcon(Transform target, Color color, float scale = 1f)
{
if (Instance == null || Instance.iconPrefab == null) return;
if (Instance.trackedIcons.ContainsKey(target)) return;
GameObject icon = Instantiate(Instance.iconPrefab);
MinimapIcon minimapIcon = icon.GetComponent<MinimapIcon>();
if (minimapIcon == null)
minimapIcon = icon.AddComponent<MinimapIcon>();
minimapIcon.Initialize(target, color, scale * Instance.iconScale);
Instance.trackedIcons[target] = minimapIcon;
}
/// <summary>
/// Remove a tracked icon from the minimap.
/// </summary>
public static void UnregisterIcon(Transform target)
{
if (Instance == null) return;
if (Instance.trackedIcons.TryGetValue(target, out MinimapIcon icon))
{
if (icon != null)
Destroy(icon.gameObject);
Instance.trackedIcons.Remove(target);
}
}
/// <summary>Zoom in the minimap.</summary>
public void ZoomIn()
{
currentZoom = Mathf.Max(minZoom, currentZoom - zoomSpeed);
}
/// <summary>Zoom out the minimap.</summary>
public void ZoomOut()
{
currentZoom = Mathf.Min(maxZoom, currentZoom + zoomSpeed);
}
private void CleanupDestroyedIcons()
{
List<Transform> toRemove = new List<Transform>();
foreach (var kvp in trackedIcons)
{
if (kvp.Key == null || kvp.Value == null)
toRemove.Add(kvp.Key);
}
foreach (var key in toRemove)
{
if (trackedIcons.TryGetValue(key, out MinimapIcon icon))
{
if (icon != null) Destroy(icon.gameObject);
}
trackedIcons.Remove(key);
}
}
}
/// <summary>
/// Minimap icon that follows a world-space target.
/// </summary>
public class MinimapIcon : MonoBehaviour
{
private Transform target;
private float heightOffset = 40f;
public void Initialize(Transform trackedTarget, Color color, float scale)
{
target = trackedTarget;
transform.localScale = Vector3.one * scale;
Renderer rend = GetComponent<Renderer>();
if (rend != null)
rend.material.color = color;
// Place on minimap layer
gameObject.layer = LayerMask.NameToLayer("Minimap");
}
private void LateUpdate()
{
if (target == null)
{
Destroy(gameObject);
return;
}
Vector3 pos = target.position;
pos.y = target.position.y + heightOffset;
transform.position = pos;
}
}