Search Unity

Resolved Major issue with input system

Discussion in 'Input System' started by Sauron1234, Apr 29, 2022.

  1. Sauron1234

    Sauron1234

    Joined:
    Sep 22, 2014
    Posts:
    29
    just when I was starting to get the hang of it and thinking maybe just maybe its not so bad.... this:


    InputActionMap userControls = new InputActionMap();
    newInput = userControls.AddAction("Jump");
    newInput.AddBinding("<Keyboard>/space");
    userControls.Enable();


    now, I push "play" and run code from another script:

    if ( GamePrefs.userControls.FindAction("Jump").triggered )
    {
    Debug.Log("Jump!");
    }


    wonderful! works great. but let's change the "Jump" to.... fire? Change in both place, of course:



    InputActionMap userControls = new InputActionMap();
    newInput = userControls.AddAction("Fire");
    newInput.AddBinding("<Keyboard>/space");
    userControls.Enable();
    Debug.Log("initialization script=" + userControls.FindAction("Fire"));


    now, I push "play" and run code from another script:

    if ( GamePrefs.userControls.FindAction("Fire").triggered )
    {
    Debug.Log("Fire!");
    }
    Debug.Log("player control script j=" + userControls.FindAction("Jump"));
    Debug.Log("player control script f=" + userControls.FindAction("Fire"));



    console log:
    initialization script=Action[/Keyboard/space]
    player control script j=
    player control script f=
    Error!!! NullReferenceException: Object reference not set to an instance of an object


    What the heck is going on here????????!!!!!!!!!!!
    Am I missing something?!
     
  2. Sauron1234

    Sauron1234

    Joined:
    Sep 22, 2014
    Posts:
    29
    I think I had a copy somewhere else with:


    InputActionMap userControls = new InputActionMap();
    newInput = userControls.AddAction("Jump");
    newInput.AddBinding("<Keyboard>/space");
    userControls.Enable();


    ..... Im not sure why neither Jump or Fire debug was giving me anything. but after removing this is solved the issue.