I’m trying to resize a custom cursor that I’ve put into my game. I’ve read on the forum that using CursorMode.Auto will automatically resize to what Unity wants your cursor size to be, so I set my cursor with CursorMode.ForceSoftware, but when I do that the cursor is completely off center… It’s center on the Y axis just fine, but it’s wayyyy to the left on the X axis… Is this a bug? If not, how can I fix it?
CursorMode determines how the cursor is rendered, not explicitly what size it is. Generally speaking, if you’re targetting desktop platforms using Auto should be fine. It’ll fallback to software rendering for you.
Make sure your texture is set as Cursor in the import settings and that it is 32x32
It isn’t taking the size of the texture… I’ve changed the resolution in photoshop now about 10 times… It started as 128x128… I’m not up to 1536 and the cursor is always 32x32 on the screen. Also, I have tried changing the max size value in the import settings. Still nothing.
32x32 is required. If you want to resize the cursor you need to resize the actual pixels of the texture (not the dimensions of the texture itself). Making it anything bigger than 32x32 via import settings or otherwise is just taking up memory.
How can you set the pixels without losing its color, though? The Color[ ] size must be at least width*height, but how would you rebuild the color array to match how it looked to begin with?
@fire7side , I’ve tried using ForceSoftware mode, but the cursor is never in the right spot. I can set the hotspot just fine, which from my knowledge is only where the ray is casted from the image to detect a mouse click, etc. I’ll upload a pic to show you what’s going on.
My actual mouse cursor is where the blue box is. I know this because it is originally white, and it changes color in an OnMouseEnter function. The cursor generated from SetCursor using ForceSoftware is way off to the left… It seems to be correct on the Y axis, but on the X axis it is definitely not working.
Resize the pixels via Photoshop. No reason to do it in code. What I mean (and it’s surprisingly difficult to explain actually) is to resize the “image” not the dimensions of the canvas.
I have questions about your “test”. Are you changing the color to something other than blue with OnMouseExit? Have you logged the mouse coordinates to double check?
OnMouseExit changes it back to white. It’s funny because I have it set to if my mouse gets too close to the edge of the screen it will pan the camera in that direction (like an RTS game). When I get my actual mouse close to the edge of the screen, it pans accordingly. All I can do is see the cursor that is generated by SetCursor… It definitely isn’t lined up with my real mouse cursor. If I set it to CursorMode.Auto it is lined up perfectly, but one of my cursors are too small.
And okay, I think I understand what you mean by resizing the pixels in photoshop. I’ll give it a try.
We’ve always used Auto. No reason to not use hardware rendering on desktop platforms. If a single texture isn’t working then I would hazard to guess something is wrong with the texture or its import settings.
The red circle is my cursor that is generated with SetCursor… As you can see, it is at the bottom left of the screen… Which SHOULD give me the coordinates of (0,0,0), or at least somewhere around that. But, as you can see in the red rectangle the coordinates are (462,85,0)
Okay, I’ll see about resizing the pixels in photoshop. Still not exactly sure what you mean lol, but I’ll give it a shot… How does one resize an image without resizing its canvas? xP
Okay, so I went to Image > Image Size and tried to resize it that way… Still no luck… Any links you could possibly throw me that could explain what you mean?
Hmm, I just have a laptop and software mode works fine. My cursor is 128x128. I suppose it’s how much you are taxing the system. I send a ray through the cursor vector and it lines up perfectly with objects which is all I need, and I’d rather have larger cursors for my purpose.
I’m having the same issue as Epictickle. Using “Hardware” mode for your custom mouse cursor forces your cursor to be 32x32, which is what Kelso is saying. But that’s really tiny! If you’re playing in 1920x1080 resolution, your mouse is hard to see when it’s that small. I’ve made my texture as big as it possibly can be to fill up the 32x32 canvas and there’s just no getting around the fact that the canvas size is locked at 32x32. How can people think this is an okay size? lol.
There should be a way to resize your hardware custom cursor, but I have a feeling this would require messing with the operating system itself, and something apart from Unity.
Hardware cursors perform and work the best, but you can’t see them. And software cursors you can re-size and adjust settings, but they perform like poo. You can’t win either way lol.
Ok I was struggling with this stuff. Finally solved.
Set cursor icon to “cursor mode” and Max size set the cursor size you’ll be interested in.
The place this script on the first scene of your game. In editor the size stuff works BUT the center spot for some reason is shifted, but in the build its ok, so enable to check visual look and size but dissable for menu navigation as you test it in editor.
autoCenterHotSpot sets your cursor hotstopt in the center automatically.
Hope this helps someone.
using UnityEngine;
using System.Collections;
public class ui_Menu_Cursor : MonoBehaviour {
//depending on source image size <<i.e Photoshop Edit-->ImageSize>> you need to adjuts the center of the mouse.
//public float centerX;
//public float centerY;
public Texture2D cursorTexture;
public CursorMode cursorMode = CursorMode.Auto;
public bool autoCenterHotSpot = false;
public Vector2 hotSpotCustom = Vector2.zero;
private Vector2 hotSpotAuto ;
void Start () {
Vector2 hotSpot;
if ( autoCenterHotSpot) {
hotSpotAuto = new Vector2(cursorTexture.width*0.5f, cursorTexture.height*0.5f);
hotSpot = hotSpotAuto;
}
else {hotSpot = hotSpotCustom;}
//Cursor.SetCursor (cursorTexture, new Vector2( centerX,centerY) ,CursorMode.ForceSoftware);
Cursor.SetCursor (cursorTexture, hotSpot ,CursorMode.ForceSoftware);
}
}
I was having the same issue. To fix it, after replacing the cursor sprite, make sure to go back to the player settings and set it to none. Then reapply the cursor sprite. Not sure why it doesn’t update automatically