Change OS cursor, runtime

Hello,
The Cursor system does not seem to work if a custom texture is not provided. I get this warning:

“Runtime cursors other than the default cursor need to be defined using a texture.”

I don’t want to define custom texture for each cursor, for each operating system… I want native OS cursors (the little hand, the arrows etc.). I tried to implement it by myself but the ICursorManager interface (see Cursor.cs, line 59) is marked as internal. Any way to solve this?

In this post there’s the code I wanted to try for Windows

2 Likes

Problem is that we would possibly want something else public (ref: Cursor.defaultCursorId) but would also need MouseCursor to be available in runtime, however it is currently defined in the UnityEditor.UIElements namespace. I do not have a solution today for you unfortunately.

1 Like

Thank you @sebastiend-unity . At the moment I settled for the texture definition, not very happy about it but it works. This is my .uss:

.unity-button {
    cursor: url('/Assets/_Project/_UI/Resources/Cursors/aero_link-4.png') 6 0;
}

.unity-base-text-field__input {
    cursor: url('/Assets/_Project/_UI/Resources/Cursors/beam_r-4.png') 15 15;
}

.unity-base-dropdown__item {
    cursor: url('/Assets/_Project/_UI/Resources/Cursors/aero_link-4.png') 6 0;
}

.unity-two-pane-split-view__dragline--horizontal {
    cursor: url('/Assets/_Project/_UI/Resources/Cursors/size3_r-4.png') 15 15;
}

.unity-two-pane-split-view__dragline--vertical {
    cursor: url('/Assets/_Project/_UI/Resources/Cursors/size4_r-4.png') 15 15;
}

(tip for the future readers: you can find the cursors in C:\Windows\Cursors and you can convert the .cur files tp .png easly with online tools)

3 Likes

If it works for you now, it’s a good solution :wink:

Having this problem with the documented “arrow | text | resize-vertical | resize-horizontal | link | slide-arrow” values in the cursor property:

Using any of the preset values raises the same warning. I can’t imagine that this is not a bug.

In Unity 2023.1.0a6 the SliderInt > Label uses a SlideArrow cursor and triggers this warning.

https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-16384

It’s not explained in the documentation but the error message is right here:
Runtime cursors other than the default cursor need to be defined using a texture.

We still don’t have a solution for this today.

1 Like

Thanks, then why does the SliderInt > Label use a non-default cursor?

Sorry, that’s clearly a bug. Would you mind reporting it?

Yes, the report is here: Jira Service Management

It seems elements like the Min-Max Slider do try to load cursors if used in runtime UI. Yet there is no way to just tell it to use the default cursor. The warnings issued are annoying.

Runtime cursors other than the default cursor need to be defined using a texture.
UnityEngine.UIElements.UIElementsRuntimeUtilityNative:UpdateRuntimePanels ()

I wonder if there is already (or at least planned) inclusion of default cursors (default, pointer, wait) in UIToolkit so that there will not be necessary to create/include user’s own textures for those standard cases in builds?
The feature seems quite obvious, it was unpleasant surprise to find out it’s missing…

1 Like