Forum rules - please read before posting.

Toggle Cursor or keyboard-controlled menus

My game is currently played with keyboard/controller, which works as intended.

Some testers have reported that some of the (rather complex) menus should have support for mouse control, which is also a non-issue.

  1. However, I would like to always disable the mouse cursor outside of menus. Having mouse functionality in the actual game would really mess things up, since it reads the mouse click as if I want to interact with the hotspot the characters stands at, and not the one it's pointing at. And since the character can only be moved using the arrow keys, the mouse cursor would only confuse players.

I was looking for a "when turn on/off menus" to be able to change this setting globally, so I don't have to implement it for each and every menu separately.

  1. How do I best create an options setting to toggle how menus are navigated? The menu element 'toggle' confuses me. There's only room for one action list; how do I create separate actions for the two states?

Comments

  • I was looking for a "when turn on/off menus" to be able to change this setting globally, so I don't have to implement it for each and every menu separately.

    You can hook into the OnMenuTurnOn / OnMenuTurnOff custom events to run code whenever a menu is turned on or off, but which setting specifically are you looking to change?

    Is there also a pattern to which menus you want to react to, e.g. only those that pause the game?

    How do I best create an options setting to toggle how menus are navigated? The menu element 'toggle' confuses me. There's only room for one action list; how do I create separate actions for the two states?

    If you link a Toggle element to a Global Bool variable, then its value will be updated each time it is clicked by the user. In the ActionList that runs when clicked, you can use the Variable: Check Action to determine the variable's value, which will match the Toggle's state.

    To have this value be treated as options data (i.e. survive game restarts and be independent of save-game data), set the Global variable's Link to property to Options Data.

  • Thanks for the clarification on toggle elements.

    Well for the first part, I want to be able to control the menus with a mouse cursor (which is easy), but the rest of the game should be controller only (it should not respond to mouse clicks at all). I don't find the right combination of settings for this.

  • Manager field values can be changed through scripting at runtime, but it's first necessary to know which values you want changed.

    You can uncheck the various Directly-navigate menus options at the top of the Menu Manager to allow for cursor-control in menus.

    When using Keyboard Or Controller input, however, the cursor is simulated. You can switch over to Mouse And Keyboard input when turning a Menu on to bring back the system cursor, though you'd also need to use the Engine: Manage systems Action to unlock the cursor if you've previously locked it.

    In what way are mouse-clicks affecting the rest of the game, and what inputs have you defined that are mapped to "mouse 0" / "mouse 1"?

  • edited January 2023

    If I choose Mouse and Keyboard, the menus are navigated fine using the mouse, but the rest of the game reacts to mouse clicks as if I interact with the hotspot that the character is standing at (colliding with) regardless of where the cursor is, i.e. identical to the space button, which I use for interactions.
    This is confusing. I would like to disable mouse clicks when I'm not in a menu.

  • You can switch your game's Input method - along with any Manager field - dynamically through scripting. It's important to first learn which fields need changing.

    To change a Manager field value through scripting, right-click the field's label to copy an API reference to it. In the case of "Input method", this is:

    AC.KickStarter.settingsManager.inputMethod
    

    To change its value, create a C# script with public functions that set it to different value, e.g.:

    using UnityEngine;
    using AC;
    
    public class InputChanger : MonoBehaviour
    {
    
        public void SetToKeyboard ()
        {
            KickStarter.settingsManager.inputMethod = InputMethod.KeyboardOrController;
        }
    
    
        public void SetToMouse ()
        {
            KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;
        }
    
    }
    

    To call these functions, and in-turn update the input method, attach this to a new GameObject, make it a prefab, and then use the Object: Call event Action to trigger the prefab's SetToKeyboard / SetToMouse functions.

    Just be aware that changes made to Manager fields will survive the exiting of Play mode - so you'll need to use the same technique to set the input method to your intended default value when the game begins. This can be done by using another such Action in your game's ActionList on start game asset, assigned at the top of the Settings Manager.

  • edited January 2023

    I know I also have to disable "directly-navigate"* for the mouse to work properly.

    so this variable is called
    AC.KickStarter.menuManager.keyboardControlWhenPaused
    but how is it used in the script?

  • edited January 2023

    Argh, scratch that, it's just me being stupid. The mouse part works!
    Just need a final nudge to disable all the directly-navigated parts!

  • The keyboardControlWhenPaused etc variables?

    You can incorporate those into the above functions, i.e.:

    public void SetToKeyboard ()
    {
        KickStarter.settingsManager.inputMethod = InputMethod.KeyboardOrController;
        AC.KickStarter.menuManager.keyboardControlWhenPaused = true;
    }
    
    public void SetToMouse ()
    {
        KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;
        AC.KickStarter.menuManager.keyboardControlWhenPaused = false;
    }
    
  • Excellent, everything's working splendidly! Thanks a bunch :)

  • Ok turned out there was one more hurdle - when I test the game in the editor, everyhing works fine, but in the compiled game the cursor is not visible.
    I haven't checked any "hide cursor" option or anything.

    The mouse clicking itself works, it's just invisible.

    Is there a piece of code I can add under the SetToMouse function?

  • What platform are you building to, and what are your AC/Unity versions?

    Do away with the custom script temporarily - does it still occur?

    If so, keep it disabled and share screenshots of your Settings and Cursor Managers.

  • edited January 2023

    Sorry, this is just me being silly again. There's indeed a "show cursor never" setting that I'd accidentally checked.
    Never mind!

    Edit:
    Although it'd be nice if I could enable this together with the input method, so I don't need to have the cursor visible when it's not used.

    should it be formated like
    AC.KickStarter.cursorManager.cursorDisplay = CursorDisplay.OnlyWhenPaused;

    ?

  • Yep, that would do it.

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.