Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Index Outside of Bounds with Input (no idea what I'm doing)

Discussion in 'Input System' started by khanstruct, May 31, 2023.

  1. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    Admittedly, I understand very little of the new Input System. (It didn't exist when I last used Unity.) Specifically, I don't understand the "subscribing to events" part... so I haven't been doing that.

    That being said, most of my code works. All of it, in fact. However, when I press the Tab key to enable my GUI canvas, I get the attached errors.

    As I said, the code does work. The GUI appears, and the game switches to the UI Action Map. When I press Escape, the GUI disappears, and it switches back to the Player Action Map (with no errors).

    I realize that this error is referring to some behind-the-scenes Unity code, and of course I know what IndexOutOfRange means, but what am I doing wrong to cause this?

    Untitled-6.png
     
  2. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    If this helps, this is the code on my CharacterController script:
    Code (CSharp):
    1. public void OpenMenu(InputAction.CallbackContext context)
    2.     {
    3.         if (menuController != null)
    4.         {
    5.             menuController.OpenMenu(context);
    6.         }
    7.     }
    And this is the code in the MenuController script:
    Code (CSharp):
    1. public void OpenMenu(InputAction.CallbackContext context)
    2.     {
    3.         if (context.started)
    4.         {
    5.             menuCanvas.enabled = true;
    6.             playerInput.SwitchCurrentActionMap("UI");
    7.             switch (context.control.name)
    8.             {
    9.                 case "i":
    10.                     //open inventory
    11.                     MenuTab(1);
    12.                     break;
    13.                 case "c":
    14.                     //open crafting
    15.                     MenuTab(2);
    16.                     break;
    17.                 case "f":
    18.                     //open friendship
    19.                     MenuTab(3);
    20.                     break;
    21.                 case "m":
    22.                     //open the map
    23.                     MenuTab(4);
    24.                     break;
    25.                 case "j":
    26.                     //open the journal
    27.                     MenuTab(6);
    28.                     break;
    29.                 case "t":
    30.                     //open trophies/collections
    31.                     MenuTab(7);
    32.                     break;
    33.                 default:
    34.                     MenuTab(0);
    35.                     break;
    36.             }
    37.         }
    NOTE: The integers in the switch/case will refer to specific tabs in the GUI.