Unity — Custom cursor controller

MonoBehaviour that swaps the system cursor on hover, click, and drag using the Cursor.SetCursor API.

Recipe

using UnityEngine;
using UnityEngine.EventSystems;

public class CursorController : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
    public Texture2D defaultCursor;
    public Texture2D hoverCursor;
    public Vector2 hotspot = new Vector2(4, 4);

    void Start() {
        Cursor.SetCursor(defaultCursor, hotspot, CursorMode.Auto);
    }
    public void OnPointerEnter(PointerEventData _) {
        Cursor.SetCursor(hoverCursor, hotspot, CursorMode.Auto);
    }
    public void OnPointerExit(PointerEventData _) {
        Cursor.SetCursor(defaultCursor, hotspot, CursorMode.Auto);
    }
}

Notes

This is the minimum viable code to ship a custom cursor in Unity 2022/2023. It does not handle per-state cursors (hover, drag, busy) — for that, see the matching tutorial linked below. It also assumes your cursor PNG is imported with point/nearest filtering; if your engine defaults to bilinear, the cursor will look fuzzy on HiDPI.

Hotspot tuning

Every snippet above passes a hotspot vector (often (4, 4) for an arrow, (8, 8) for a hand). The hotspot is the pixel inside the image that counts as the click point. If your cursor "feels off," adjust by single pixels. The hotspot tuning tutorial has the full debugging workflow.

Where to get a cursor pack

If you have not designed a cursor yet, browse CursorCraft collections for ready-made packs, or pick a free CC0 pack from the community assets page. The design-your-own tutorial walks through making one from scratch.