I have a project I’ve been working on for several years. Lately I’ve been working on content and haven’t touched the code base for many months. To preview my content, I run the game in play mode and move my little character/camera rig around with the WASD/mouse. This has been working fine for months.
Suddenly, today, I’m finding that my input will work normally the first time I click “play” after starting the Unity editor. Subsequent times the game (in play mode) accepts no input. Pressing keys or moving the mouse does nothing in the game. There are no errors or messages in the console. It’s like the game window is just not receiving any input at all. I believe this is some sort of bug in the Unity editor.
If I restart the editor, Input will work again but only first time entering play mode. If I enter play mode again, input is broken again. Through experimenting, I also discovered that if I can trigger the assembly definitions to update then Input will also work again for just one play (for example, if I update a script or install/uninstall a script asset).
Conceivably, I can work around this issue if every time I want to enter play mode I modify a random script in some trivial way (like add space, delete the space and save). This is annoying, though.
Does anyone know if there is some sort of cache I could try clearing to fix this? Just deleting the library does not work.
Deleting the Library folder did not fix the issue. reverting to a default editor lay-out did not fix the issue. Input works fine in build. I’ve been using Unity 2021.3.16f1 LTS but I’ve updated to 2021.3.45f1 (the latest) to see if installing a new version would fix the issue. I’m using the OLD input system.
… so compare today’s version of the project with the last source control commit. You do use source control, right? Any multi-year-long project should.
So imagine this … you haven’t touched your project for months. Suddenly, it stops working. Did you change the editor version today? Because if not, it is extremely unlikely to be a bug in the editor.
That sort of bug will not just suddenly occur if you truly did not make any changes to your project. It’s almost certain to be a change in the project (which in turn could trigger a bug but nevertheless it’s a change in the project). If not that, it’s some change in the system including possible data corruption, antivirus blocking something, things like that.
That sounds a lot like an issue with disabled domain reload. Do you have domain reload disabled to enter playmode instantly? If so, try setting it back to the default to see if the issue disappears.
If so it’s most likely some static field (including static events) not getting reset. This can occur even in packages, but the editor won’t update these unless you tell it to (or upgrade the editor version). Since you use old input system there should not be any static fields interfering (I believe it is entirely encapsulated in C++ unlike the new Input System). So it must be something in your own code, or any code in the project including 3rd party assets. Check anything that could have statics and affect input processing.
If it’s not that I bet it is some execution order issue. You don’t know you have one until it starts to surface for whatever reason. Typically these occur between editor and build or other highly different code execution paths, not randomly, but they might. They may even occur with a seemingly innocent change, such as moving a component up or down in the Inspector list of components. This can lead to Start() or similar to run in a different order.
I take it that means you haven’t updated the editor version before the issue started to occur. Hence you need to compare the last known good version of the project with today’s. If you can’t do that due to not using source control, you will be in a bit of pain analyzing this and hopefully also learn a lesson.
Thanks for the detailed analysis. Lots of good ideas there.
Specifically I was thinking of a corrupt file. I’ve had this happen before where a prefab or scene started acting funny. Then I would delete it and recreate it identically and then it would work fine again from there on out. As you mentioned a source control “diff” would reveal if that’s the case.
Spot on! This fixes the problem. I’m still gonna look for the actual cause, but this is a much better work around than before.