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

Unity Input System NullReferenceException while executing 'performed'

Discussion in 'Input System' started by DemetriusParham, Jul 29, 2021.

  1. DemetriusParham

    DemetriusParham

    Joined:
    May 17, 2020
    Posts:
    1
    While the game is on the title screen, if I press the X button on my PS4 gamepad, the debugger displays the error message that I included. I'm not sure why I'm getting this error. I'm new to coding in Unity.

    Code (CSharp):
    1. public class MenuPrac : MonoBehaviour
    2. {
    3.     PlayerController playerControl;
    4.     TitleScreen titleScreen;
    5.     //TitleSceneController titleSceenController;
    6.     SceneController sceneController;
    7.     public static MenuPrac instance;
    8.     List<GameObject> listOfButtons = new List<GameObject>();
    9.     int i = 0;
    10.     FadeUISection _settingsUISection = new FadeUISection();
    11.     // Start is called before the first frame update
    12.     void Awake()
    13.     {
    14.         instance = this;
    15.         instance.titleScreen = new TitleScreen();
    16.         instance.playerControl = new PlayerController();
    17.         instance.sceneController = new SceneController();
    18.  
    19.  
    20.         instance.playerControl.Gameplay.Select.Enable();
    21.         instance.playerControl.Gameplay.MoveUp.Enable();
    22.         instance.playerControl.Gameplay.MoveDown.Enable();
    23.  
    24.         instance.playerControl.Gameplay.MoveUp.performed += ctx => HighlightPreviousOption();
    25.         instance.playerControl.Gameplay.MoveDown.performed += ctx => HighlightNextOption();
    26.         instance.playerControl.Gameplay.Select.performed += ctx => SelectOption();
    27.  
    28.        
    29.         //this.playerControl.Gameplay.enabled();
    30.         //playerControl.Gameplay.Cancel.performed += ctx => HighlightNextOption();
    31.      
    32.         //GameObject originalGameObject = GameObject.Find("Buttons");
    33.     }
    34.  
    35.  
    36.  
    37.     void HighlightNextOption()
    38.     {
    39.         if(this.i == 3)
    40.         {
    41.             //EventSystem.current.SetSelectedGameObject(listOfButtons[0]);
    42.             instance.i = 0;
    43.         }  
    44.         else
    45.         {
    46.             //EventSystem.current.SetSelectedGameObject(listOfButtons[0 + i]);
    47.             instance.i++;
    48.         }
    49.  
    50.     }
    51.  
    52.     void HighlightPreviousOption()
    53.     {
    54.         if (instance.i == 0)
    55.             instance.i = 3;
    56.         //EventSystem.current.SetSelectedGameObject(listOfButtons[3]);
    57.         else
    58.             instance.i--;
    59.             //EventSystem.current.SetSelectedGameObject(listOfButtons[i - 1]);
    60.     }
    61.  
    62.     void SelectOption()
    63.     {
    64.         if (instance.i == 0)
    65.         {
    66.             if (playerControl != null)
    67.                instance.titleScreen.StartGame();
    68.                 //this.titleScreen.StartGame();
    69.             else
    70.                 return;
    71.         }
    72.         else if(instance.i == 1)
    73.         {
    74.             instance.titleScreen.ShowSaveSlots();
    75.         }
    76.         else if(instance.i == 2)
    77.         {
    78.             instance._settingsUISection.Show();
    79.         }
    80.         else
    81.         {
    82.             instance.titleScreen.Exit();
    83.         }
    84.     }
    85.        
    86.      void OnEnable()
    87.     {
    88.         instance.playerControl.Gameplay.Enable();
    89.     }
    90.  
    91.      void OnDisable()
    92.     {
    93.         instance.playerControl.Gameplay.Disable();
    94. }
    Here's the error

    Code (CSharp):
    1. NullReferenceException while executing 'performed' callbacks of 'Gameplay/Select[/DualShock4GamepadHID/buttonSouth]'
    2. UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
    3. UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
     
  2. MigleDing

    MigleDing

    Joined:
    Jul 6, 2021
    Posts:
    9
    got the solution already? having the same issue