Having problems getting ANY value out of Input.GetAxis()

This is my entire Driver class:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Driver : MonoBehaviour
{
    [SerializeField] float rotationSpeed = 0.5f;
    [SerializeField] float forwardSpeed = 0.0125f;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        float steerAmount = Input.GetAxis("Horizontal");
        float forwardAmount = Input.GetAxis("Vertical");
        Debug.Log("steerAmount: " + steerAmount);   
        //transform.Rotate(0, 0, -steerAmount);
        //transform.Translate(new Vector3(0, forwardSpeed, 0));
    }

}

No matter what key I use (W, A, S, D, or arrow keys) the output is 0.

Iā€™ve looked at the InputManager in Project Settings and aside from 30 entries in the Axis list, it all looks appropriate. I can add a screenshot if that would help, but Iā€™m at wits end here. Iā€™m going to have to go back to using GetKeyDown until this can be resolved.

Let me know what I can submit here to help in solving this.

There is a similar thread from someone experiencing the same issue as yours:

One thing to add here would be to check if you are even using the old input system, which you can double check in the Player Settings --> Player expand the Other Settings drop-down menu and look for Active Input Handling, but if you can use the Input.GetKey() methods than you probably are already

Also make sure that you have configured the Key or Mouse Button as the type in the Input Manager

Let me know how that goes

Active Input Handling is set to ā€˜Input Manager (Old)ā€™

Thatā€™s the thing, I canā€™t even get the Input.GetKeyDown(KeyCode.A) method to return a true condition even if I am pressing the A key.

The odd thing is that this same code is working perfectly in a different project I was working on in a different tutorial. However, in this one, I canā€™t seem to get any input methods to work. I have tried GetAxis, GetKeyDown, GetKey. None seem to be working in this courses project.

Looking at the quoted persons topic, I seem to be having the same problem he is, where no keyboard input is working at all. I donā€™t have an Event System in my Hierarchy.

I am really at a loss, since other projects I was working on are working fine with the GetKeyDown and GetKey methods. They didnā€™t use the GetAxis method.

I tried putting Debug.Log(Input.GetAxis(ā€œHorizontalā€)) in one of my other projects and itā€™s working perfectly!

I started Delivery Driver in 2021.3.37f1(LTS) and have changed it to 2022.3.24f1(LTS) thinking that the older version may have been the issue. As far as I can tell, its not. I am currently in 2022.3.24f1(LTS) in both projects now. One works as expected and the Delivery Driver project is not.

If you donā€™t mind, do share a screenshot of your Input Manager with us. Just expand the first horizontal dropdown menu & do as well compare your configuration with the other projects yourself if it works there.

As this is a small project for the time being (I guess), consider migrating your current project to a new one, otherwise we would need to take a deeper look

Funny thing I have created a new project, added a Sprite2D, created a script and added it to the sprite2D object, in the Update method added the Debug.Log(Input.GetAxis(ā€œHorizontalā€)) and I still get 0ā€™s.

I compared the two project settings from the working input system and non-working input system. They look the same, but there are a lot of settings I didnā€™t open. I just opened the Horizontal.

I have a 3D project I have been working on following ā€œCode Monkeyā€™sā€ tutorial Kitchen Chaos. GetAxis works fine in that project too.

Iā€™m just going to take this opportunity to uninstall Unity and reinstall it on an SSD drive. Iā€™m not a complete newb when it comes to programming. Just to Unity. Iā€™m learning, but this problem has me totally stumped.

Iā€™ll let you know if reinstalling has a positive result.

If you get 0ā€™s then as mentioned above, you have set up a different type in the Input Manager. Make sure to use Key or Mouse Button

Can you zip up the project, upload it somewhere and share it? I can look at it and if itā€™s a Unity problem, I would get the same behaviour, but if itā€™s hardware or something, then it would work for me as expected. I could also see if I can solve it, should I also get the same behaviour

Iā€™m a little new to using Google Drive to share a file. Let me know if this link doesnā€™t work and Iā€™ll try something else.

That project is a brand new project created with a newly installed Unity and a newly installed 2022.3.26f1 editor version.

I would love for there to be something stupid I have done to mess this up.

Thanks for all your guys help so far.

Dave

So, hereā€™s what happened:

  • I downloaded your project but didnā€™t have the same Unity version (2022.3.26f1) so I opened it in 2022.3.5f1 instead. All worked as expected.
  • Downloaded 2022.3.26f1 and opened it there. All worked as expected.
  • Deleted the project and unzipped it again (suspected the 2022.3.5f1 ā€˜downgradeā€™ changed some things) and this time opened it in 2022.3.26f1. Broken
  • Closed Unity, deleted the ā€˜Library Folderā€™ and opened it again. Broken.
  • Then I saw itā€¦

image

The game window is not focused. Clicking on it would give it focus and then controls will work. Changing that to ā€˜Play Focusedā€™ or ā€˜Play Maximisedā€™ will also forward focus to the game window and then it should be fine.

1 Like

Keen observation, sometimes itā€™s the small details that can make a big difference. Iā€™ll keep that in mind if it pops up again

Oh my goodness guys! Thank you SO, SO, SO much! I did change that setting in other projects, I just didnā€™t realize that it had that kind of effect on the input manager!

I really thought I had broke something or made a change to a setting deep inside something that wasnā€™t going to be seen!

Obviously, Iā€™m never going to forget this again! I guess that setting is for testing a program when the game window looses focus.

Thanks again guys! You are lifesavers!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms