Console Null Reference Error but everything works fine

Hi everybody,
iI have lines of codes that’s move my rigidbody2d and it’s working fine but when iI run it, unity’s console give me an error of:

everything works fine but it’s gets on my nerve when its showing me an error any way to resolve the problem?

here is the code:

Vector2 movementVertical = Camera.main.transform.up * inputDevice.LeftStickY * MovementSpeed * Time.deltaTime;
                   
                    Vector2 movmentHorizantral = Camera.main.transform.right * inputDevice.LeftStickX * MovementSpeed * Time.deltaTime;
                   
                    m_Rigidbody.MovePosition (m_Rigidbody.position + movementVertical + movmentHorizantral);

Thanks

We most likely are going to need more code in order to resolve. That code doesn’t show us how you are assigning your variables in order to find which one may be null.

Additionally, since some references are set through inspector, and SS would be great.

    void Update ()
    {
        inputDevice = InputManager.ActiveDevice;
   
    }
   

    void FixedUpdate ()
    {
        Move();
    }

    void Move()
    {
        movementVertical = Camera.main.transform.up * inputDevice.LeftStickY * MovementSpeed * Time.deltaTime;
       
        movmentHorizantral = Camera.main.transform.right * inputDevice.LeftStickX * MovementSpeed * Time.deltaTime;
       
        m_Rigidbody.MovePosition (m_Rigidbody.position + movementVertical + movmentHorizantral);
    }

I’m guessing the problem is with the InControl Assets that im using in Update()

A Null Reference error stops code in its tracks. If everything is working despite the Null Reference, there are two possibilities:

  1. The code finishes doing everything that you can see it doing before the line in which the NRE is triggered. Since the rigidbody is being moved in the last line of code here, that must not be the case.
  2. There are multiple copies of this script running. It’s really easy to add a script to the wrong object and not notice, and if m_Rigidbody is something you assign by the “drag-in-inspector” method, that would be null, and would explain this error.
    Try putting this anywhere in your script:
Debug.Log("Test: "+gameObject.name, this);

When you click on it, it’ll highlight the object that called it.