Apple M2 Pro running MacOS Sonoma 14.4 running Unity 2022.3.9f.1 and Rider 2023.3, with the JetBrains Rider Editor 3.0.27 package
So my team is running into an issue recently that has had all of us stumped. Simply put, switching between two branches (our primary Dev branch and our Refactor branch that we’re synchronizing with Dev every two weeks) causes compile errors that go away on destroying and rebuilding the Library folder (generally we’re just using Recompile All in the Unity Editor and it’s doing that for us).
These compile issues are always one of two types: error CS0234: The type or namespace name ‘’ does not exist in the namespace ‘’ (are you missing an assembly reference?)` error CS0246: The type or namespace name ‘’ could not be found (are you missing a using directive or an assembly reference?)
The files containing these classes exist exactly where they should and the code in them hasn’t changed, but when we view them in Rider, they’re no longer part of the project, despite being in the same location surrounded by files that ARE part of the project. We can confirm then that they’re missing from the appropriate csproj file.
These issues can be resolved by doing a Reimport All in the Library in Unity Editor (or manually destroying the Library folder with Unity Editor closed and letting it rebuild when re-opening it), or by dragging the missing scripts from their current folder to another one then back, after which Unity usually adds them to the csproj file.
Next time you change branch between Dev and Refactor, we have the same exact issue with usually the same few files no longer being included in the csproj file. I’ve also tried just deleting the csproj files and using Regenerate Project Files in Settings → External Tools with Embedded packages and Local packages checked, and that actually doesn’t resolve the problem and the same scripts end up missing from the csproj files.
So my question is, why might these scripts (which have meta files and everything and reside in the same folder as other included scripts) sometimes not being included when the csproj files get regenerated, and how can we correct this problem so we’re no longer having to rebuild the library every single time we swap between the two branches?
When switching branches, do you have the Unity project open? And Rider? Or both?
I absolutely avoid switching branches on an already open project. Though that behaviour may depend on what tools you use (mine is SourceTree on Windows).
At the very least, the branch switching process must be completed before bringing the editor back into foreground. If you perform the switching with an editor script that spawns a (background) git process, then this could be your issue.
On occassion I also have to restart Rider because it gets desynched with the editor somehow and won’t recover until restarted. This represents itself with missing highlights, or highlighting files with errors that don’t have any errors.
Generally, I’m keeping Rider and Unity both open while switching branches, and for the prior 4 years I’ve been on this project, it hasn’t been an issue. We’ve also been using the two branches for a few months and this only started happening about 2-3 weeks ago. I AM making sure to let the entire Git checkout finish before touching the Unity Editor again, and I’ve tested using GitHub Desktop, Rider, and command-line Git to do the checkout and the problem occurs regardless of the Git tool. I’ve also tested with Rider closed the entire time to make sure it wasn’t triggering Unity to respond to the file changes before the checkout is finished, and it didn’t actually matter if it was open.
I tested just restarting Unity instead of doing a Recompile All or destroying the Library folder and it seems like it’s enough just restarting Unity every time I change branches. This doesn’t feel like it should be necessary though, and more-over, it seems like if I’m doing a Reimport on the entirety of the Library in the Unity Editor, and running Regenerate project files, that should be accomplishing the same task of making sure that Unity is aware of the scripts that have moved and properly adds them to the project files. Hypothetically, if I made all the same file changes that Git is doing for me when switching branches, but manually, I think this issue would still be happening.
My goal is to figure out what condition could be causing these same 5 or so files to be left out of the csproj that Unity is generating, even when manually regenerating it. I think knowing that would be enough for me to be able to figure out what difference between the branches is causing this to happen, because it’s not ideal for me to have to close and reopen Unity 10-20 times a day when working in a single project the entire time.
What are these classes that are supposedly missing? Your own code?
I can imagine that perhaps some package dependent on the Roslyn analyzer gets thrown off.
Could also be an editor script that bypasses the editor, perhaps using its own directory monitoring.
Does a right-click => Refresh (Ctrl+R) also fix the issue? If so that would certainly indicate that the AssetDatabase is not in synch, and didn’t pick up some changes. In that case it could be a broken editor script that either calls DisallowAutoRefresh or Start/StopAssetEditing without ref-counting or safeguarding (try/finally) those calls.
Or Preferences => Asset Pipeline => Auto Refresh or Directory Monitoring being disabled.