Forum rules - please read before posting.

Unity UI Cursor not changing when hovering over UI menus

Hi Chris, I wonder if you can help. I am using a Unity UI Cursor for my cursor. However, for UI prefabs menus my cursor will not change when hovering over them. Can you help me work out to make the cursor change over specific UI menus?

Please see pdf with further info and screenshots

https://drive.google.com/file/d/1_xvApiqxzb_9ULXvbFtzdV5JaYXsNhPs/view?usp=sharing

«1

Comments

  • Currently, only the RawImage will be affected when hovering over such elements. If you're controlling the display with animation, that'll override this texture.

    I should, however, be able to add the ability for the "Cursor ID" parameter to respond to menu elements. I will look into this as part of the next update.

  • Hi Chris. Is this featured in the new update?
  • It is. From the Changelog:

    • Fixed: Unity UI Cursor's "Cursor ID" Animator parameter not responding to Menu Element changes in the active cursor icon
  • edited December 2022

    ok, I have updated to latest AC but my UNity UI cursor is still not changing. If you check the PDF link above, does my cursors animator have the correct variables and parameters for this to work?

  • Check the Animator controller's "UseIconID" parameter value. Is that updating when hovering over elements?

  • yes it is, goes to -1 on the UI menus

  • It should be -1 when normally over menus, but switch to the ID of the specified cursor (0 for Use) when over that element.

    This is the behaviour I get when testing on my end. Try it on yours with the default Menu Manager's InGame menu.

  • so my UseIconID when just on the cursor mode is -1, and changes accordingly when hovering over hostpots correctly, and my CursorID changes the same as UseIconID also, however, menu I hover over the menu the MenuOverideID changes (but only on menu) but nothing else changes when over a menu

  • Forget UseIconID - that's me looking in the wrong place. CursorID should be the one that changes.

    There may be a conflict with your other components, however.

    Temporarily remove your Cursor Script component, so that AC's provided Unity UI Cursor is the only script component attached to it. Does that change the behaviour of the CursorID parameter?

  • Please see video here, when I turn off cursor script it only shows UseOnly action

    https://drive.google.com/file/d/13Z8PtOLoAu4Ond-jkUK1N8-eoa7jJW0m/view?usp=share_link

    You'd need to tell me if essentially it works with CursorScript off? And then what to do to ensure my animations / Cursor way works, thanks!

  • Ignoring the animations not running correctly, the CursorID is being correctly set to 0 when you now hover over the button without CursorScript.

    This suggests CursorScript is overriding the value of CursorID, so you'll need to prevent this from happening by commenting out any code that calls Animator.SetInteger for "CursorID".

  • edited December 2022

    ok so I have commented out this line:

    _animator.SetInteger ("CursorID", KickStarter.playerCursor.GetSelectedCursorID ());
    

    And now the cursor works as it should elsewhere, but not on the menus? it is just normal cursor, what do I need to do now to make it change to a specific cursor on menus?

    The commented out line is from this section of code

    int menuOverrideID = KickStarter.playerMenus.GetElementOverCursorID ();
            _animator.SetInteger ("MenuOverrideID", menuOverrideID);
            _animator.SetInteger (useIconIDParameter, useIconID);
            _animator.SetBool (hasLookIconParameter, hasLookIcon);
            //_animator.SetInteger ("CursorID", KickStarter.playerCursor.GetSelectedCursorID ());
            _animator.SetInteger ("InvID", (KickStarter.runtimeInventory.SelectedItem != null) ? KickStarter.runtimeInventory.SelectedItem.id : -1);
            _animator.SetBool ("IsInCutscene", KickStarter.stateHandler.IsInCutscene ());
    
  • And now the cursor works as it should elsewhere, but not on the menus?

    Was the cursor working elsewhere but the menus not the original issue?

    it is just normal cursor, what do I need to do now to make it change to a specific cursor on menus?

    The Unity UI Cursor script should set CursorID correctly if you prevent your own script from overriding it, but this is how you can set it manually:

    int cursorID = KickStarter.playerMenus.GetElementOverCursorID ();
    if (cursorID < 0) cursorID = KickStarter.playerCursor.GetSelectedCursorID ();
    _animator.SetInteger (cursorIDIntParameter, cursorID);
    
  • I’ll try and figure out how to use your suggested code.

    Was the cursor working elsewhere but the menus not the original issue?

    Yes
  • So Chris, what should I do next, sorry?

  • Replace:

    _animator.SetInteger ("CursorID", KickStarter.playerCursor.GetSelectedCursorID ());
    

    with:

    int cursorID = KickStarter.playerMenus.GetElementOverCursorID ();
    if (cursorID < 0) cursorID = KickStarter.playerCursor.GetSelectedCursorID ();
    _animator.SetInteger (cursorIDIntParameter, cursorID);
    
  • I get this error

    Assets/Sleepytime Village/Scripts/CursorScript.cs(93,23): error CS0103: The name 'cursorIDIntParameter' does not exist in the current context

  • int cursorID = KickStarter.playerMenus.GetElementOverCursorID ();
    if (cursorID < 0) cursorID = KickStarter.playerCursor.GetSelectedCursorID ();
    _animator.SetInteger ("CursorID", cursorID);
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.