Forum rules - please read before posting.

New Input system and AC

Hi @ChrisIceBox
I need some help or a better explanation. I have added the new inout system and added the ControlsReader prefab to the scene. Everything is working fine, but there are a couple of things that are not working, please see the list.
1. I have created a ToggleJournal button in the "Control" asset that came with the AC download, I have assigned the key but it is not working. It does not call the Menu.
2. It does not navigate the menu and conversations directly when I use the controller.

I am using the defualt AC UI, so I pressume I need to add that to the ControlsReader?

Thanks Chris

PS: I am using Unity 2019.4 and AC 1.76.1

Comments

  • I have created a ToggleJournal button in the "Control" asset that came with the AC download, I have assigned the key but it is not working. It does not call the Menu.

    You'll need to add this input to the ControlsReader prefab's "Input Action References" Inspector field before it will be read by AC. Are you having this issue after having down so?

    It does not navigate the menu and conversations directly when I use the controller.

    Is your Menu's Source set to Adventure Creator or Unity Ui Prefab. If the latter, temporarily switch to the former - does it work then?

  • Hi @ChrisIceBox thank you for your reply. I have added the controls to the Input Action Refrences and that is working now, thanks.

    The menu source is set to use Adventure Creator.

  • Is this a menu that pauses the game while open?

    Make sure that Directly-navigate Menus when paused? is checked at the top of the Menu Manager - though this is also necessary when using the old Input Manager.

  • Hi @ChrisIceBox so that is not technically what I want to do. Doe sthe ControlsReader read the gamepaf automatically? So when the player uses the keyboard and mouse the Directly-navigate Menus when paused? is false and when the player uses a gamepad it must be set to true automatically. With Rewired this was easy to do but I am struggling with the new unity Input system.

  • First check that the option being checked gives you the right behaviour when using a gamepad. The option can be toggled on/off using scripting, but it's important to know the correct combination of settings for each input method beforehand.

    A sample script that can alter these options based on input can be found here:
    https://adventure-creator.fandom.com/wiki/Switching_input_method_dynamically

    It's intended for Input Manager, however, not Input System. Input System isn't the easiest to get the "last device used" from, but it should be possible. First though, let's make sure that the options mentioned are enough to get the behaviour with just a gamepad.

  • Hi Chris sorry no this is not working. Because I am using the new input system it cannot ready the Input.anyKeyDown the script works if I switch the input system manaully.

  • I'm only mentioning the script at this stage - it will have to be adapted to be compatible with Input System. First, we'll need to be sure of which Manager field values should be changed through the script.

    You say the script works when switching to the old input system, but does it have the intended effect?

  • Hi Chris I got it sort of working in a hacky way. What I ended up doing was by adding the SwitchInputs.cs script to the ControlsReader prefab as this prefab is in all of my scenes already. Then I adapted the SwitchInputs.cs script to the following:
    `
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    using UnityEngine.InputSystem;

    public class SwitchInputs : MonoBehaviour
    {
    private Controls _input;
    [SerializeField] private InputMethod defaultInputMethod;

    private void Start()
    {
        _input = new Controls();
        SetInputMethod(defaultInputMethod, true);
    }
    
    private void Update()
    {
        if (Gamepad.current.startButton.wasPressedThisFrame)
        {
            SetInputMethod(InputMethod.KeyboardOrController);
            Debug.Log("Controller is active");
        }
        else
        {
            if (Keyboard.current.anyKey.wasPressedThisFrame)
            {
                SetInputMethod(InputMethod.MouseAndKeyboard);
                Debug.Log("Keyboard is active");
            }
        }
    }
    
    private void SetInputMethod(InputMethod inputMethod, bool force = false)
    {
        if (KickStarter.settingsManager.inputMethod != inputMethod || force)
        {
            KickStarter.settingsManager.inputMethod = inputMethod;
    
            switch (inputMethod)
            {
                case InputMethod.MouseAndKeyboard:
                    KickStarter.menuManager.keyboardControlWhenCutscene = KickStarter.menuManager.keyboardControlWhenPaused = KickStarter.menuManager.keyboardControlWhenDialogOptions = false;
                    // Set any mouse/keyboard-specific settings here
                    break;
    
                case InputMethod.KeyboardOrController:
                    KickStarter.menuManager.keyboardControlWhenCutscene = KickStarter.menuManager.keyboardControlWhenPaused = KickStarter.menuManager.keyboardControlWhenDialogOptions = true;
                    KickStarter.playerMenus.FindFirstSelectedElement();
                    // Set any keyboard/controller-specific settings here
                    break;
    
                default:
                    break;
            }
        }
    }
    

    }
    `

    It now reads the controller and keyboard from the input system.

  • Looks good.

    I've also updated the Input System integration package with a similar technique that can be used to run a custom script function when the control scheme is changed.

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.