Hello all, new user to the Input System, have watched as much as I can on the subject, and also read up on the docs, but I must be missing something as I am trying to get the UI to work with my game.
I’m the lead programmer for my final university group project, so it is kinda important that I can get this done fast. Apologies for any massive images on here, the “thumbnail” process was incredibly tiny it seemed.
So for reference, I don’t want to use the built in “Player Input” or “Player Input Manager” systems, as they aren’t flexible enough, and have actually presented a few problems, so I’ve gone on and made my own script to handle player input. Very basically, I have one Input Asset, with a Player and UI action map (seen in pictures below).
For debugging purposes, I just have two spheres, both having the same “Input” script I wrote in there.
I’ll comment along the way what I’m doing too.
[SerializeField] private InputActionAsset _input; //Grab the Input Asset.
[SerializeField] public int gamePadId; //Simple ID to get the two controllers I have plugged in
[SerializeField] private Canvas canvas; //Canvas object to disable and enable the canvas on "start" click.
private InputActionMap _actions; //Custom Action Map -> mainly for player movement
private InputActionMap _UI; //Custom Action map -> for the UI
private InputActionMap finalInputAction; //A tried and failed attempt to combine the action maps.
private Vector2 dir; //My direction variable
private bool gamePaused; //Pause variable
private InputUser newIP; //New InputUser made to the world view so I can reference it in lower methods.
void Awake()
{
InputActionAsset ac = Instantiate(_input); //Instantiate the Input Asset
//Make a new InputActionMap for each Action Map.
_actions = new InputActionMap();
_UI = new InputActionMap();
finalInputAction = new InputActionMap();
_actions = ac.FindActionMap("Player"); //Grab the "Player" Map from the Input Asset
_UI = ac.FindActionMap("UI"); //Grab the "UI" Map from the Input Asset
//This was a tried and failed method to combine the Player and UI inputs.
foreach (InputAction iA in _actions.actions)
{
finalInputAction.AddAction(iA.name, iA.type);
Debug.Log(iA.name);
}
foreach (InputAction iA in _UI.actions)
{
finalInputAction.AddAction(iA.name, iA.type);
Debug.Log(iA.name);
}
//Create and assign a new Input user with the Gamepad being the ID set in the field
newIP = InputUser.PerformPairingWithDevice(Gamepad.all[gamePadId]);
//This one works for player movement, but it will override UI and any other action maps.
//newIP.AssociateActionsWithUser(_actions);
newIP.AssociateActionsWithUser(finalInputAction); //Failed attempt to combine Player and UI maps.
//Assigning the Input Actions so I can set them to a custom function
InputAction movement = _actions.FindAction("Movement");
InputAction pause = _actions.FindAction("Pause Menu");
//Now just assigning the input actions lambda expressions and functions.
movement.performed += ctx => dir = ctx.ReadValue<Vector2>();
movement.canceled += ctx => dir = Vector2.zero;
pause.performed += PauseMenu;
canvas.enabled = false;
}
public void OnEnable()
{
//Enable all Action maps on startup
_actions.Enable();
_UI.Enable();
finalInputAction.Enable();
}
public void OnDisable()
{
//Disable all Action maps on shutdown
_actions.Disable();
_UI.Disable();
finalInputAction.Disable();
}
private void PauseMenu(InputAction.CallbackContext context)
{
//Simple pause script, sets timescale to zero, turns the gamePaused to true or false, and enables the canvas.
if (!gamePaused)
{
Time.timeScale = 0f;
gamePaused = true;
Debug.Log("Paused");
canvas.enabled = true;
newIP.AssociateActionsWithUser(_UI);
}
else
{
Time.timeScale = 1f;
gamePaused = false;
Debug.Log("UnPaused");
canvas.enabled = false;
newIP.AssociateActionsWithUser(_actions);
}
//The AssociateActions seems to override any actions when I apply the new one, so I tried that, but it also just threw a bunch of errors.
}
private void OnMoveChange(InputAction.CallbackContext context)
{
dir = context.ReadValue<Vector2>();
}
void Update()
{
transform.position += new Vector3(dir.x, transform.position.y, dir.y) * 4.0f * Time.deltaTime;
}
For reference, here are the errors:
Map index on trigger does not correspond to map index of trigger state
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:117)
Exception 'IndexOutOfRangeException' thrown from state change monitor 'InputActionState' on 'Stick:/XInputControllerWindows/leftStick'
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:117)
IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEngine.InputSystem.InputActionState.ChangePhaseOfAction (UnityEngine.InputSystem.InputActionPhase newPhase, UnityEngine.InputSystem.InputActionState+TriggerState& trigger, UnityEngine.InputSystem.InputActionPhase phaseAfterPerformedOrCanceled) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview/InputSystem/Actions/InputActionState.cs:1530)
UnityEngine.InputSystem.InputActionState.ProcessDefaultInteraction (UnityEngine.InputSystem.InputActionState+TriggerState& trigger, System.Int32 actionIndex) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview/InputSystem/Actions/InputActionState.cs:1242)
UnityEngine.InputSystem.InputActionState.ProcessControlStateChange (System.Int32 mapIndex, System.Int32 controlIndex, System.Int32 bindingIndex, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview/InputSystem/Actions/InputActionState.cs:902)
UnityEngine.InputSystem.InputActionState.UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (UnityEngine.InputSystem.InputControl control, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Int64 mapControlAndBindingIndex) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview/InputSystem/Actions/InputActionState.cs:783)
UnityEngine.InputSystem.InputManager.FireStateChangeNotifications (System.Int32 deviceIndex, System.Double internalTime, UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview/InputSystem/InputManager.cs:2685)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:117)
Should not get here
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:117)
Any insight or help at all would be greatly appreciated! I’ve already had nightmares trying to get the first stage (just basic player movement with separate controls) working.

