Forum rules - please read before posting.

Controller/Mouse Enable/Disable

Hi,

I’ve tried setting this up several times, but I’ve hit a wall and could use some guidance.

What I’m trying to do is show a prompt at game start that lets the player choose between two control schemes: Controller (Direct method + controller or keyboard) and Keyboard and Mouse (Point-and-click + mouse and keyboard).

Selecting Controller should set a variable to true, which enables alternate UI prompts; otherwise, the standard UI is shown.

I tried adapting the script from this thread:
https://adventurecreator.org/forum/discussion/11065/auto-detecting-mouse-and-or-controller-input

However, I’m running into issues with UI focus and refreshing after switching methods—UI elements fail to refocus on the visible elements, and when Direct control is active, the system mouse cursor can lock in place and randomly select UI elements.

I don’t need dynamic input switching based on player input. My setup is simple: each input has a Positive (keyboard/mouse) and an Alt Positive (controller), and this part works reliably.

Ideally, I’d just toggle a variable via an ActionList and switch the Movement and Input Methods, but Input Method doesn’t appear to be accessible from ActionLists. I’m considering creating a custom Adventure Creator action to control the Input Method directly. - But I'm unsure if that's the best way to approach this.

Any advice on the cleanest way to approach this would be greatly appreciated. I originally tried dynamic switching, but it introduced too many edge cases, so I’m aiming for a straightforward variable-based solution instead.

Thanks again for the help.

«1

Comments

  • What are your AC/Unity versions?

    I'm not clear if the issue is down to the inputs themslves, or the changes that need to be made at runtime based on the chosen input method.

    Before incorporating the ability to switch method at runtime (even if it's just the once), I'd recommend playing the game with Direct / Keyboard+Controller enforced, to work out what other settings need to be changed, as well as determine if the issue is present when all settings are fixed as opposed to set at runtime.

  • Hi Chris, thanks for replying so quickly. I'm using 6000.0.31f1 Unity and 1.85.3 for AC. How do I do that (playing the game with Direct / Keyboard+Controller enforced). Thank you again.

  • I just meant to set the values manually in the Settings Manager, play the game without anything dynamic, and working out what values everything should be set to before attempting to set them through script.

  • edited February 20

    Ah, that. Yes, I've done that. The problem seems to be with the system/cursor when you play in direct/controller. For exmaple, in the title screen, the menu is set up to work with direct method, but if I click the mouse once it defocuses everything and I can't get that back. The cursor also selects random menu elements and highlights them.

    I've set all menus already to select first visibile and as a help to the UI refocus issue I usually add Select Menu Element First Visible on Back Buttons when I exit menus.

    Menu elements also seem to defocus based on the "Pause Game" option in menus. For example, if I open a Menu that has the option enabled and then I go back to the initial menu (that has the option disabled), so I try to have the menu option consistent and have it either turned on or turned off for all.

  • Are you locking the cursor when under direct control, and are you letting AC spawn its own Event System?

    ACs Event System includes the Optional Mouse Input Module, which - for Input Manager - should prevent mouse input when the current game state allows for direct Menu control.

    As well as the "Directly navigate" options at the top of the Menu Manager, this also includes the "during gameplay" option from the Engine: Manage systems Action. Enabling all ought to prevent mouse input interacting with the UI at all times.

    InteractionA / B inputs, however, will still be read if they're mapped to the mouse. Are these, or any others, mapped to mouse buttons in the Input Manager?

  • Hi Chris,

    Thanks again for all your help.

    Here is a recording of my settings. I tried to incorporate every element you mentioned in your reply.

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

    Sorry about the system cursor. I tried to make it visible with the recording software, but it does not seem to be working. Whenever you see the menu elements from the prompt get deselected, that is a mouse click within the game window at runtime.

    I have also included an image of Input A and B. Yes, I use the Left and Right Mouse buttons as well as A and B on the controller.

    https://drive.google.com/file/d/1W7ajIwCvUB7aDpcZwuMVIQ7hT8-ukP/view?usp=sharing

  • The Menu uses Unity UI, I take it.

    It is not clear from your video if the Event System is being generated by the Menu Manager. What is its full Inspector?

    The image link gives me a "file does not exist" page.

  • edited February 22

    https://drive.google.com/file/d/1H0a4bX-xz9fKPTKvmgTFlsgu2uYQS2x6/view?usp=sharing < sorry about that, don't know what happened there.

    Here's a screenshot of the Inspector for the Event System - https://drive.google.com/file/d/1abRIrSSrt_a6Tq-ReaLgpiMJL5RnhmNY/view?usp=sharing

    Yes, All my Menus sources are Unity UI Prefabs or Unity UI in Scenes.

  • And this Event System - is this a part of the scene file? It is not using any of AC's input code.

    The Event System being used here is for Input Manager - but it's giving a warning about Input System being used instead. What is your Active input handling set to in the Project -> Player settings, and are you using Input System in any way?

    Removing the Event System from the scene will allow AC to generate its own.

  • The Event System generates at runtime when any given Scene is started. I am using the Old Input System. Active Input handling is set to "Both". Could that be the issue? Would setting it to "Old" fix it?

  • "Both" is best used as a fallback when Input System is used, but some remnants of Input Manager remain.

    It should be set to Old, but that likely won't be enough. The real issue is that the Event System is not the AC one.

    If it's not in the scene, is it a custom prefab listed at the top of the Menu Manager? AC will not generate its own one if there is a custom one assigned. Check also the Console for any messages related to the Event System.

  • edited February 24

    Event System Prefab field (In Menu tab) seems to be set to "None". I've enabled the Debug options but there's nothing pertaining to Event System. I was able to make 1 scene work as intended but I have no idea how. I resolved the issue found here https://drive.google.com/file/d/1abRIrSSrt_a6Tq-ReaLgpiMJL5RnhmNY/view?usp=sharing and now when I click the mouse gets ignored and it runs on the method I set (Direct).

    I also set to Old Input System. The problem seems to be when you switch Scenes, it seems to generate the same Event System with the same error. I tried as an experiment to create a prefab from the EventSystem that seems to work and assign it in the Event System Prefab field (In the Menu tab), but the same issue occurs as in the screenshot I shared.

    Note: After setting up a prefab the Event System seems to appear outside of runtime in the scene. Deleting that and letting the prefab set generate its own seems to fix the issue. I think I need to go in every scene and see if that object is present?

    If this fixes the click issue, would the toggle on/off method I suggested work as a viable option? I'd still need a way to manually change Input Method via Action List. Would a custom action be possible for that?

    Sorry for the wall of text.

  • I think I need to go in every scene and see if that object is present?

    Yes - you need to ensure that your scenes do not have an Event System object. It one is present, this will override the one that AC spawns (whether that be its default one, or the assigned prefab).

    It's important to know that Unity likes to auto-generate an Event System object in Edit mode, when you create new Canvas objects. It may be that this is being added inadvertently to your scenes.

    If this fixes the click issue, would the toggle on/off method I suggested work as a viable option? I'd still need a way to manually change Input Method via Action List. Would a custom action be possible for that?

    It's probably a case of using either a variable or a custom Action, rather than both. A custom script could listen out for changes to a variable's value, and make adjustments to your settings accordingly.

  • edited February 25

    Alright. I'll start cleaning the scenes of those event systems. Question about the best set-up for Direct and Point and Click when switching.

    Movement Method: Direct
    Direct-nav-in-game Menus
    Player: Constrain: Cursor Lock: Enabled. (this applies in only a few places, generally this would not be Enabled)
    Input Method: Keyboard or Controller.

    Point and click:
    Movement Method: Point and Click
    Direct-nav-in-game Menus <- Does this option need to be enabled once and that's it? can it be kept enabled for Point and Click for simplicify sake?
    Player: Contrain: Cursor Lock: Disabled
    Input Method: Mouse and Keyboard.

    Is this alright or am I missing anything?

    As always thank you in advance.

  • Direct-nav-in-game Menus <- Does this option need to be enabled once and that's it? can it be kept enabled for Point and Click for simplicify sake?

    You typically want to be sparing with this, as it'll cause any Menu that shows during gameplay to be navigable. This'll include the InGame menu from AC's default interface.

    Depending on your game's design, it may be fine to have it be set once - but you should leave it disabled when using Point and Click.

  • So the script also needs to include enable/disable for the direct navigate when paused and directly navigate during conversations when the controller/variable is enabled/disabled?

  • I apologize for the length of this thread. I just want to ensure the switch occurs without any issues, as I am preparing for the full release. Life would have been much simpler if I had just stuck with Point-and-Click.

    This is my setup so far: I have a variable ( Lin kto Options data) that is set via a prompt at the beginning of the game. Setting it to false selects Mouse/Keyboard; setting it to true selects Controller. On the title screen, I added a script that listens for any change in that variable.

    Everything seems to work fine, but now I am experiencing some freeze/unfreeze shenanigans. Specific menus seem to lock interactions until I open and close the Inventory. I am not sure if the method switch is causing the issue or if I forgot about a change in the Engine Manager System: Interactions. Anyway, I will try to figure that out.

    C#
    using UnityEngine;
    using AC;

    public class InputMethodMonitor : MonoBehaviour
    {
    private static InputMethodMonitor instance;

    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
            return;
        }
        instance = this;
        DontDestroyOnLoad(gameObject);
    }
    
    private void OnEnable()
    {
        EventManager.OnVariableChange += OnVariableChange;
    }
    
    private void OnDisable()
    {
        EventManager.OnVariableChange -= OnVariableChange;
    }
    
    private void Start()
    {
        GVar variable = GlobalVariables.GetVariable(292);
        if (variable != null)
        {
            RefreshSettings(variable.BooleanValue);
        }
    }
    
    private void OnVariableChange(GVar variable)
    {
        if (variable.id == 292)
        {
            RefreshSettings(variable.BooleanValue);
        }
    }
    
    private void RefreshSettings(bool isDirect)
    {
        if (isDirect)
        {
            // Input and Movement
            KickStarter.settingsManager.movementMethod = MovementMethod.Direct;
            KickStarter.settingsManager.inputMethod = InputMethod.KeyboardOrController;
    
            // Menu Navigation Settings
            KickStarter.menuManager.keyboardControlWhenPaused = true;
            KickStarter.menuManager.keyboardControlWhenDialogOptions = true;
        }
        else
        {
            // Input and Movement
            KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
            KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;
    
            // Menu Navigation Settings
            KickStarter.menuManager.keyboardControlWhenPaused = false;
            KickStarter.menuManager.keyboardControlWhenDialogOptions = false;
        }
    }
    

    }

  • If you have a freezing behaviour, try using the AC Status box to see if it indicates the cause.

    If you want to include the Direct navigate when paused? option in your script, you can do that with:

    KickStarter.playerInput.CanKeyboardControlMenusDuringGameplay = false;
    
  • Hi, sorry for the late reply. It seems that the Pause issue isn't resolved and I don't exactly know why. I created a new menu and set up the basics and removed any possible depency to test this. This issue is sort of outside the scope of this thread so if you like I can start a new one I've attached a video with what is happening and the set-up.
    I honestly can't figure out why it's doing this. It has a different Input set-up to avoid conflicts, I've created a fresh new menu to avoid any sort of dependency, it's set-up exactly like the Inventory/Character menu which seems to work as intended. But when I toggle On/Off it doesn't always seem to work consistently. My theory initially was that maybe it's due to spamming the key, but I can spam the key on the Character menu and that one works just fine. You can see in Ac Status that it's successfully changing Game States. There's no Action List added to ZTurn On or Turn Off in the Menu to account for this, nor is there any Event running that could cause this.

    https://drive.google.com/file/d/1dUZd5YUGLxZgSudROnuha55O-YsyXZ6Z/view?usp=sharing

  • edited March 3

    I'm afraid I'm not clear on which issue the video is reporting - is it that you're not able to mouse over Hotspots after closing the menu?

    If Hotspots have become non-detectable, the two main potential culprits are that the mouse considers itself to be over a menu, or that Hotspots are no longer detected via mouse position.

    Unchecking Unity UI blocks interaction and movement? in the Settings Manager may reveal if it's the former. Otherwise, check the Hotspot detection method setting at the time this occurs.

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.