Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom Cursor in UWP on Xbox One

Discussion in 'Windows' started by AllisonSalmon, Aug 21, 2017.

  1. AllisonSalmon

    AllisonSalmon

    Joined:
    Nov 13, 2016
    Posts:
    18
    We are currently working on a title that is using a custom cursor, set using SetCursor. When we build and run a UWP build on PC the custom cursor works. However, when we run the same build on Xbox One we are seeing a large system cursor (XAML build type) or no cursor (D3D build type). In both cases we are using the IL2CPP scripting backend. Is there any documentation on how to correctly setup and use custom cursors through Unity for UWP builds on Xbox One?
     
  2. AllisonSalmon

    AllisonSalmon

    Joined:
    Nov 13, 2016
    Posts:
    18
    OK, slight update. So it IS showing our custom cursor but with XAML builds the system cursor is also visible. If I disable mouse mode it disables the system cursor but our in game cursor does not move. The custom cursor also is there in a D3D build but not getting input either.

    Is there away to disable the visibility of the system cursor and still get the "mouse" location passed into the game?
     
  3. phipro

    phipro

    Microsoft Employee

    Joined:
    Aug 19, 2013
    Posts:
    123
    Hey Allison,

    This is something we are improving in a future update, but right now only a workaround is available which basically involves rendering your custom cursor, and updating with the pointer movement updates.

    So, rendering and updating position with OnPointerMoved event

    I've talked with the platform team on this, and if you are trying to disable the cursor, setting the CoreWindow's PointerCursor to null should do the trick.

    Let me know if this helps or not..

    Thanks,
    Phil
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    The workaround sounds like using Software Cursor option in Unity. Did you try that?
     
  5. AllisonSalmon

    AllisonSalmon

    Joined:
    Nov 13, 2016
    Posts:
    18
    Sorry for the slow response to this thread, we had other games we were working on shipping that took my time away from this project. We are still having issue with this.

    First off this is all on Xbox One running a UWP build.

    Here is an outline of what we would like to do:
    1. We would like to show the Unity software cursor.
    2. We have several custom cursors we switch to through out the game using SetCursor.
    3. We would like to drive this cursor with the controller.
    4. We would like to hide the Xbox system cursor completely

    Here is what I have tried and the results

    XAML build:
    • Set PointerCursor to null. This makes the system cursor go away until I call Unity's SetCursor and move the joystick then the system cursor reappears.
    • If we don't use the SetCursor to set a customer cursor I don't see a cursor at all in Unity.
    • We tried setting the PointerCursor to null ever frame and that works to hide the cursor but then the unity software cursor will initially move but then stop getting position updates.
    • I tried setting up the OnPointerMoved call back and use that position to drive a sprite around the screen. That works briefly then the callback stops getting called.
    D3D build:
    • The pointer position is always reporting as large negative numbers. Unity's SetCursor shows up but doesn't get driven by the controller.
    Any advice on what to try next would be greatly appreciated. Thanks!
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    Can I ask what Unity version you're using, there were improvements for Cursor in Unity 5.5. In the past to hide a cursor we also were setting PointerCursor to null, but as you know this has undesired side effects - like pointer events no longer being received, what we did instead we created a fully transparent cursor in Windows resource file and whenever we needed to hide system cursor we simply assigned that to PointerCursor.

    If you're on Unity 5.5 or higher, you can try this yourself by doing:
    Code (csharp):
    1.  
    2. PointerCursor =  new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Custom, 1000)
    3.  
    1000 is hardcoded value in resource file for hidden cursor
     
  7. AllisonSalmon

    AllisonSalmon

    Joined:
    Nov 13, 2016
    Posts:
    18
    Hi @Tomas1856! This sounds exactly like what we would like to do. Were using 5.6 but I just upgraded to 2017 because I ran into the issue with the new update to visual studio.

    I have tried this and it does initially hide the cursor but I see the system cursor return as soon as I move the controller joystick.
     
  8. AllisonSalmon

    AllisonSalmon

    Joined:
    Nov 13, 2016
    Posts:
    18
    Oh and just wanted to add again that this seems to be a problem only when running on Xbox. On PC running the same build the cursor is hidden and stays hidden.
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    I have been investigating this for the past couple of days. It seems that assigning null to CoreWindow PointerCursor will hide the cursor on XAML mode, but will make the app not receive mouse events at all. Stay tuned.

    The only workaround I can think of that will work right now is not going through mouse input at all and instead drawing a cursor yourself and moving it when desired controller inputs are pressed.
     
  10. mahdi-po

    mahdi-po

    Joined:
    Jan 18, 2016
    Posts:
    7
    hi
    i using unity 2018.1.2.f1
    i have problem with mouse input it cant be recognize with xbox one x both in XAML and D3D mode
    but it work on visual studio run on lockalmachine
    joystick and keyboard work on xbox d3d mod and xaml but mouse not detecting
    i checked the event system force to enable true but didn't help for mouse detection...
    i need mouse in my xbox app and app must be fullscreen(d3d mode as i know)
    please help me
    any solution would be grate appreciated.
    thanks alot
     
    Last edited: Aug 14, 2018
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Unfortunately Xbox One does not support using physical mouse.
     
  12. mahdi-po

    mahdi-po

    Joined:
    Jan 18, 2016
    Posts:
    7
    thanks for your reply
    but such a bad news for me its very awful...
    do you know what is the reason?
    even any android devices supports physical mouse why not xbox one x(win 10 device) support one of the old's input device?
     
  13. mahdi-po

    mahdi-po

    Joined:
    Jan 18, 2016
    Posts:
    7
    actually in developer mode i can see the mouse cursor and i can control it with my physical mouse so xbox one can recognize mouse device but it banned to use it in app right?
    is there any way to active the mouse in app too?
     
  14. alexhapki

    alexhapki

    Joined:
    May 8, 2015
    Posts:
    32
    For a game intended for Xbox and PC I tell what I am doing, it might not be the best idea, nor even a good one, but hey, it is working for me.

    1) Simple UI, such as main menu, nothing too complicated, mouse works as usual, and if a controller is detected, then I have an overlay that is moved with the stick of the gamepad from one Rect to another rect. When fire button (green A button in Xbox controller) is pressed, it performs an action depending on when the overlay is. If overlayRect == newGameRect -> change scene to new scene.

    2) for complicated UI, e.g. an inventory system. I have use real game objects with sprites and colliders, making it look as a UI. If a controller is detected, a gameobject with collider is moved through the input system, and when pressed any button, the collider detects where to perform an action, e.g. clicked next player. This action is called on a central script I call InventoryController.
    If there is no controller, mouse use a raycast, it detects what gameobject is on, then call same function on Inventory Controller.

    Check the images below. I have just started making it. So it is a very basic draft. You can see more how it is working well on;
    https://partner.steamgames.com/apps/landing/1278580

    Inventory0.PNG
    Inventoryv1Unity.PNG