After upgrading a project from 2019.4 to 2020.2 I am experiencing an issue with the Resources class.
When the editor is launched a call to Resources.Load that happens in Awake fails, unless I reimport any asset in the project. I don’t really need to reimport the asset I am trying to load (a prefab) but any asset in the project, even a texture. To be even more clear: the path of the prefab is correct and the code did not change at all, only the editor version changed. Builds are not affected by this.
In your case, does this happen every time you reopen the project? Or just every time you reopen the project until you perform this little Reimport step? Do you happen to be using the Addressables package in your project?
Any time you upgrade you should make a full back up of your project and then delete the Library folder in your project (with Unity closed), and then reopen Unity to let it reimport all.
The Library folder is where Unity builds the “partially built stuff” that ultimately goes into your game.
When you upgrade versions, you generally want Unity to recreate all this stuff again. This is the same as doing a Reimport-All from your project, but it forces Unity to be honest and not have bugs.
Hi, I do have a backup (git) and I have also tried deleting the lib folder already, I should have pointed that out. Actually I have already reverted to 2019 but I was hoping somebody else experienced something like this and could help. Thanks for your time anyway.
It happens when I re-open the project and every time I have to do the re-import thingy. And I am not using addressables so far, although it’s a dependency for another package I am using.
Also, a workaround is changing Zenject so it loads that prefab using the AssetDatabase #if UNITY_EDITOR. That works and in builds the issue doesn’t seem to repro, so it should be fine. But it’s very hacky.
I just upgraded from the latest 2018 LTS to the latest 2019 LTS and ran into this issue straight away. It looks like it might be a bug with Asset Database V2, because I can reliably make the issue go away by rolling back to V1. Might be worth a try on your project just to confirm that’s where the problem lies.
A lot of constructors in Unity are NOT called by the main thread.
Most of the Unity API can ONLY be used from the main thread.
Because of how these IOC are designed to emergently work based on dependency rules you set up, it can be very easy to call a bunch of stuff NOT on the main thread in Unity, and then that stuff… doesn’t work, because it isn’t supposed to work off the main thread.