Movement detection only intermittently working

Ok, so this is very weird and I feel like I’m imagining it. But, it’s happening, and I’d like to try and understand why so hoping someone could help me.

I was following along with Rick, but when I pressed play and tried the game, I was getting no value detected from the Input.GetAxis, it was just printing out zeroes:
image
Also the console log wouldn’t scroll, I had to keep putting it down to the bottom. (I guess Unity is thinking it’s just the same messages so not bothering to scroll?)

I fiddled around for a while but couldn’t see anything I’d done wrong. In the end, I went to Github and found Rick’s code for the lesson. This had Horizontal and Vertical, which I hadn’t got to, but anyway I pasted it into my Update function:

And voila, this worked:
image
Input values displayed. They end up showing either 1 or -1 depending on which direction I hold, and they stay there. The log also scrolls.

So great, working. But I want to know what I did wrong, because Rick’s not always going to be there with code for me to copy! I’ve gone through my commented lines character by character and they are identical with what I copied from Rick. So, I started doing some testing. I thought maybe there was something in my Unity setup that meant it wouldn’t work without both axes. So I commented out Rick’s Vertical lines and tried. Aha! It stopped working. I put them back. Uh-oh. Still not working. I put mine in. Still not working. I’ve re-ordered, added arbitrary extra Debug statements - nothing again.

So I deleted the contents of the Update function except my commented original lines, and pasted back in from Rick’s code on Github. Pressed play. Working!! Stopped it, pressed play again, still working. Added in an extra Debug.log just with random text: input no longer read.

This is very odd, but basically the behaviour I’m seeing is: when I write exactly the same characters as Rick myself, it never works - input is always read as 0. When I paste in Rick’s code, it works. Until I make any other change to the code, at which point it stops working.

I am totally at a loss, but I can reproduce this every time. Currently I can only put this down to maybe there’s a weird Unity bug where it’s not correctly compiling the file unless … I don’t know? A special character exists that’s being pasted in from Rick’s code? There’s nothing visible. I noticed in the video that Rick’s VS Code shows character encoding “UTF-8 with BOM” while mine was just “UTF-8”. I changed that to match his but it doesn’t seem to have helped. I’m currently using Unity Editor v2021.2.7f1, so a little older. I’m going to try and instal a new version and see if that helps. But I wanted to post if only because it’s getting late and I’m tired and tomorrow I might actually think this was a dream.

1 Like

It’s hard to tell what is the issue. I’m assuming you’re only showing code that works.

Get some sleep. I’m sure the issue will become obvious when you’re fresh.

2 Likes

Oh, this sounds like something I would love to solve. Can you please copy-paste the code that isn’t working so I can see what is going on?

1 Like

Thanks for the replies. I hope it makes sense later this evening on when I’ll have the chance to get back to it. I’ll post the code as well with more description.

Ok, sorry about this… Today I cannot reproduce the issue. I mean, I did. I loaded up Unity, I stripped my script file right back to my own code, and it doesn’t work. I pasted in Rick’s code, and it does work. But now if I make arbitrary changes to the file, it remains working. I’ve uncommented my original code and it has still remained working.

There does still seem to be a bug where the console showing the Debug Log is intermittently not scrolling to the bottom automatically (as Rick’s does in the video). However with the Collapsed view I’m able to verify that it’s working). I guess this made it harder to troubleshoot last night when I hadn’t thought about collapsed view.

So, apologies everyone. I must’ve been going slightly mad last night. Or maybe I did dream it. Or perhaps I encountered a really bizarre and transient error in Unity or in VS Code that has not appeared today on a fresh boot and load up of the software.

Thanks very much for the offers or help! Looks like I’m ok.

Aaaaargh!!

I spoke too soon. I moved on to the next lesson - New InputSystem, and I’m getting similar behaviour. I typed out the code EXACTLY as Rick did in the video, but it didn’t work. I didn’t get anything logged in the console this time. So out of morbid fascination I copied Rick’s whole script into mine, and it started working. (Other than one movement axis only goes to 0.7, not to 1 - but that’s surely unrelated).

I’m just about to update my Unity Editor version to see if this is all some kind of crazy bug that can go away. I think I’ll redownload and reinstall VS Code as well for good measure.

That sounds like a problem I encountered a while ago. In the Input System → Input Actions, click on WASD. If the Mode is set to “Digital Normalized”, set it to “Digital”. Then test your game again. Theoretically, you should get 1 instead of 0.7. And maybe that will also solve other problems in this context.


See also:

Thanks very much. That sounds promising. The method Rick has used so far is to create (I hope I’m getting my terminology right here) a small set of bindings within a Serialized Field in the script. So in my Project Settings, under Input System, it just tells me I don’t have an Input System Asset. I’ll follow Rick for a bit longer then I might have a play around in there. Thank you

Is there a warning or error message somewhere? If so, could you share a screenshot of the message and the context (= where it appeared)?

If you cannot find any solution for your problem yourself, which version of Unity do you use? Sometimes, Unity changes little details in their engine, and things suddenly work in a slightly different way.

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

Privacy & Terms