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