Custom mouse cursor changes color randomly

Godot Version

4.6.dev6.official

Question

I’m a total newbie experimenting with a custom mouse cursor. After a second or so, it flickers and changes color to a darker hue.It is not super clear in the GIF, probably due to compression, but in reality the color change is very noticeable. Is there anything I can do about this?

godot_bug-Animated Image (Large)

Can you post the code that changes the mouse cursor?

Just pick a single frame from the gif?

It doesnt look like the gif adds anything. Just looks like a normal static sprite except for the strange color change?

This is basically it:

func _ready() -> void:
	Input.set_custom_mouse_cursor(HandCursor, Input.CURSOR_POINTING_HAND, Vector2(18,5))

var HandCursor = preload("res://assets/SmallHandCur.png")

func _on_mouse_entered() -> void:
	Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)

func _on_mouse_exited() -> void:
	Input.set_default_cursor_shape(Input.CURSOR_ARROW)

I think the gif illustrates how the color change happens after a small delay on every mouseover, but if animated gifs are frowned upon here, I could replace it with static images.

I don’t frown at animated gifs but wonder if it adds anything to your mouse pointer. It could be that the problem with your mouse pointer shifting colors is because of one of the frames. In that case, remove that frame.

The gif compression is definitely damaging things; if you zoom in, you can see that it’s messing with the dither pattern on the button, for example. That said, it doesn’t account for the flicker.

Is this the only mouse change you’ve made? This looks like what I’d expect if you had two separate bits of code fighting over the cursor.

The code I posted above and the hand image is the entire project, so there are no other bits of code. It is just a minimal test case.

EDIT: Before and after images:

The custom mouse cursor isn’t a gif, it’s a PNG. The poster submitted a gif to show the issue.

Edit: replied to the wrong person :sob:

What is the size of the image? The docs say

image can be either Texture2D or Image and its size must be lower than or equal to 256×256. To avoid rendering issues, sizes lower than or equal to 128×128 are recommended.

@paintsimmon I know the gif is just the movie of what’s wrong (the code’s preload()is on a png), but I’m also leery of artifacts creeping into the reporting mechanism; I’ve spent entirely too much time on my own code chasing a phantom bug that turned out to be in the debug framework itself. My point there is that the gif movie is doing additional damage, so some of the symptoms we see may be a result of the movie compression.

But there’s clearly an underlying problem here unrelated to that.

The flicker there is what bothers me; it’s like the whole image is being reloaded or something.

1 Like

The image is 64 x 64 pixels, so that should not be a problem, unless it is too small somehow.

Which image is “correct”? By which I mean, presumably one of them isn’t matching the color of the source image…

looks very different

Since the default icon image is 256x256 128x128, did you make it smaller for the demonstration?

Edit: whoops got the wrong size

It is hard to say which color is correct. The color shown in Photoshop seems to match the initial, lighter tone.

I pasted your code into a new project on 4.6.dev6 and connected the signals, but the mouse cursor did not change at all. Did you change something else on the project?

I struggled too with the cursor not changing at first, but it turned out that cursor changes will not display when Godot is running “embedded” (I can’t remember the correct terminology right now.)

EDIT: Problem solved, I think. Changing the size of the png to 128 x 128 pixels seems to remove the color change and flicker (although the cursor gets pretty huge now.)

1 Like

Maybe the issue is with the detection of mouse entering and exiting? It works fine for me (even when embedded) if I instead change the mouse_default_cursor_shape to “Pointing Hand” (on the Control node) instead of using the mouse signals.

1 Like

The issue seems to be with using a 64 x 64 png as mouse cursor.

If I change the default cursor to the small png in project settings, I get the same color change behaviour even without the mouseover (it seems to happen about a second after I stop moving it around.)

This does not happen when using the larger 128 x 128 image.

2 Likes