Forum rules - please read before posting.

UI - Cursor driven interfaces with a control pad

edited September 2021 in Technical Q&A

Hello,

So far in my game all the UIs and AC menus have been useable with a mouse cursor. However, with adding control pad support into the game it raises the question how menu UI should be handled.

Is there any support, advice, or best practice for having a menu that can be controlled via a mouse cursor, but, also work without a cursor if using a control pad (so the player would highlight options before pressing a confirm button)?

Comments

  • Unity's UI Navigation tools are bit quirky. Unity's default EventSystem allows you to navigate with both a cursor and directly, but this also means that you can end up with two elements selected at the same time.

    AC relies on a custom EventSystem that forces one or the other, based on your chosen settings at the top of the Menu Manager - see the Manual's "Navigating menus directly" chapter for details on this.

    If you want to be able to rely on both, you'll want to assign an EventSystem prefab of your own into the Menu Manager. This can be just a regular copy of Unity's default EventSystem, unless you want behaviour that's more custom.

    The tricky part is the auto-selection. Unity UI canvases can't be navigated without an initial selection - pressing input buttons while nothing is selected will have no effect. AC provides options in a Menu's properties to auto-select a given element when that menu is turned on, but you may want to bypass that in favour of custom selection code that only runs if e.g. a controller is detected as being plugged in.

  • For the interim, is it possible to just have the mouse cursor controllable with a pad?

  • You can't use the system cursor with a controller, but if your input method is set to Keyboard Or Controller, and menus are not set to be directly-navigable, then the game makes use of a simulated cursor instead.

    This cursor can be moved with inputs named CursorHorizontal and CursorVertical.

    See the Manual's "Keyboard or controller input" for details.

  • edited September 2021

    Thanks.

    So far, my input method has been 'Mouse and keyboard', and after integrating Rewired I managed to adjust it to give a nice sensitivitiy to movement of the first person camera. Everything was good.

    I've tested setting the input method to 'Keyboard or Controller' which is certainly promising as it allows the controlpad to move the cursor around in menus, however camera movement in first person gameplay is suddenly super sensitive.

    Would you expect that change to occur?

    The property Cursor move speed seems to just impact cursor speed in menus. How do I adjust the speed and sensitivity of first person camera movement?

  • Ok, I think I've managed to make it feel a bit better by juggling values in Rewired and GameEngine, but only by making one super small and the other super large:

    I don't know if that strikes you as being sensible (it's massively different to the default values in both regards)

  • It's possible to override free-aiming input in the same way that other input types are. You can incorportate this into your existing ACInputRewired script to allow for a custom scale factor.

    Inside the Start function, add:

    AC.KickStarter.playerInput.InputGetFreeAimDelegate = CustomGetFreeAim;
    

    Then add the following additional function:

    private Vector2 CustomGetFreeAim (bool cursorIsLocked)
    {
        if (cursorIsLocked)
        {
            float scaleFactor = 1f;
            return new Vector2 (CustomGetAxis ("CursorHorizontal") * scaleFactor, CustomGetAxis ("CursorVertical") * scaleFactor);
        }
        return Vector2.zero;
    }
    
  • edited September 2021

    Thanks Chris. That script addition does indeed seem to calm things down.

    However I've run into a rather worrying issue with the simulated cursor approach. I have a two monitor setup, and if I build the game, and play it fullscreen, as I'm playing I can see the Windows cursor moving around on my other monitor and interacting with things.

    A similar problem exists inside Unity (I just assumed it wouldn't be present with builds - but it is) Notice how offest and active the system cursor is:

  • If you're using a simulated cursor, AC won't touch your system cursor. You can lock it manually with:

    Cursor.lockState = CursorLockMode.Locked;
    
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.