Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Change OS cursor, runtime

Discussion in 'UI Toolkit' started by Oneiros90, Feb 23, 2021.

  1. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    77
    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
     
    Nexer8 likes this.
  2. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    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.
     
    Oneiros90 likes this.
  3. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    77
    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:
    Code (CSharp):
    1. .unity-button {
    2.     cursor: url('/Assets/_Project/_UI/Resources/Cursors/aero_link-4.png') 6 0;
    3. }
    4.  
    5. .unity-base-text-field__input {
    6.     cursor: url('/Assets/_Project/_UI/Resources/Cursors/beam_r-4.png') 15 15;
    7. }
    8.  
    9. .unity-base-dropdown__item {
    10.     cursor: url('/Assets/_Project/_UI/Resources/Cursors/aero_link-4.png') 6 0;
    11. }
    12.  
    13. .unity-two-pane-split-view__dragline--horizontal {
    14.     cursor: url('/Assets/_Project/_UI/Resources/Cursors/size3_r-4.png') 15 15;
    15. }
    16.  
    17. .unity-two-pane-split-view__dragline--vertical {
    18.     cursor: url('/Assets/_Project/_UI/Resources/Cursors/size4_r-4.png') 15 15;
    19. }
    (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)
     
    kayy likes this.
  4. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    If it works for you now, it's a good solution ;)
     
  5. lsegal

    lsegal

    Joined:
    Oct 17, 2015
    Posts:
    5
    Having this problem with the documented "arrow | text | resize-vertical | resize-horizontal | link | slide-arrow" values in the cursor property:

    upload_2022-2-11_14-51-29.png

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

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
  7. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    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.
     
    Denis-535 likes this.
  8. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Thanks, then why does the SliderInt > Label use a non-default cursor?
     
  9. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Sorry, that's clearly a bug. Would you mind reporting it?
     
  10. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
  11. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,112
    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.
    Code (CSharp):
    1. Runtime cursors other than the default cursor need to be defined using a texture.
    2. UnityEngine.UIElements.UIElementsRuntimeUtilityNative:UpdateRuntimePanels ()