Forum rules - please read before posting.

Remapping keys

I've went through the https://adventurecreator.org/tutorials/remapping-controls-game tutorial but I'm unsure how I would use this script to allow the player remap controls in an AC menu?

Comments

  • edited June 2023

    The tutorial only covers the basics of overriding AC's inputs, as its relies on Unity's legacy Input Manager - which isn't well-suited to runtime changes.

    The new Input System, however, does make this more viable.

    In a test project, have a look at AC's Input System integration over on the Downloads page. This comes with its own remapping feature, which you can customise in a provided Menu.

  • I set up the new input system but now the camera control for first person player seems very sticky and weird.

  • Recreated, I believe. I'll look into it.

  • I have updated the Input System integration package with improved free-aiming behaviour with the mouse - give it a try and see if it's better on your end as well.

  • How would I get menu elements to update based on the changed buttons?

    I have labels on the ingame menu showing which button would activate different menus. These should be updated based on the player remapping.

  • You'd need to attach a script to the Text box that references the Input Action and reads its human-readable value:

    using UnityEngine;
    using UnityEngine.InputSystem;
    using UnityEngine.UI;
    
    public class DynamicInputText : MonoBehaviour
    {
    
        public InputActionReference inputActionReference = null;
        public Text linkedTextBox = null;
    
        void OnEnable ()
        {
            int bindingIndex = inputActionReference.action.GetBindingIndexForControl (inputActionReference.action.controls[0]);
            string inputKey = InputControlPath.ToHumanReadableString (inputActionReference.action.bindings[bindingIndex].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
    
            linkedTextBox.text = inputKey;
        }
    
    }
    
  • Is this possible with AC menus?

  • As in, Menus with AC as their Source option?

    I'd recommend relying on Unity UI, but otherwise you can rely on Global String Variables for each text, use Label elements to show their values, and then update the variable values instead:

    using UnityEngine;
    using UnityEngine.InputSystem;
    using AC;
    
    public class NANTest : MonoBehaviour
    {
    
        public InputActionReference inputActionReference = null;
    
        private void Update ()
        {
            int bindingIndex = inputActionReference.action.GetBindingIndexForControl (inputActionReference.action.controls[0]);
            string inputKey = InputControlPath.ToHumanReadableString (inputActionReference.action.bindings[bindingIndex].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
    
            AC.GlobalVariables.GetVariable ("MyVariable").TextValue = inputKey;
        }
    
    }
    
  • I've set up the new input system with the integration and have remappable controls working but I don't seem to figure out how to use the defaults button, atm it seems like it doesn't do anything. Pressing the button clears the variable value but the buttons in the inputs menu aren't updating to their default value.

  • Have you set up the Options-linked variable to store the inputs, described in the Readme?

  • I have, yes.

  • Recreated, thanks. I've updated the package with a fix - you only need to re-import the scripts if you've made changes to the other files.

  • That works, but shouldn't the Scale Processor Link also affect CursorVertical sensitivity instead of only Horizontal?

  • With which input, the mouse?

    The Scale processor should - by default - be attached to the Mouse inputs for both the CursorHorizontal and CursorVertical actions in the Controls asset. Is this not the case?

  • Scale processors are attached, I think the link script only has a field for one action

  • The field is configurable - add a second instance of the same component and amend the default value to CursorVertical.

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.