Replacing the default cursor by a custom Texture in Unity is quite simple:

  • Go to Edit -> Project Settings -> Player
  • Set your texture in Default Cursor
  • Adjust Cursor Hotspot to make it coincide with your new texture (cursor hotspot is where the click event is detected, i.e. the point of the mouse for the default cursor)

And you’re done! Well, almost. If the cursor still shows up as the default system cursor, or if you get a message error similar to “specified texture is not accessible by CPU”, make sure your texture as “Cursor”.

Unity actually exposes methods to swap between cursors at runtime. wintermutedigital has a guide on custom cursors which shows how to use these methods.

Now, this is a good approach but it has a major drawback: the size of the cursor is set as 32x32 and it doesn’t seem possible to make it bigger.

In this case there is a workaround:

  • Create a canvas
  • Create a child object with an image component
  • Set your cursor texture to the image component (this time set it as a normal texture or sprite, whichever works)
  • Create a component with code below and set your image object as mCursorVisual, and set displacement as needed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CustomCursor : MonoBehaviour
{
    public Transform mCursorVisual;
    public Vector3 mDisplacement;
    void Start()
    {
      // this sets the base cursor as invisible
      Cursor.visible = false;
    }

    void Update()
    {
        mCursorVisual.position = Input.mousePosition + mDisplacement;

    }
}

Using this, the texture will be moving like the cursor, and the displacement vector works in the same way as the “Cursor Hotspot” of Unity settings.

Don’t forget to remove raycasting detection from your canvas and image object.

Now, thanks to our setup, we get a resizable cursor that behaves just like a normal cursor. We can also use materials (and shaders) so we have a lot more capabilities compared to simply setting a default cursor.