Resources.Load not working unless any asset is reimported

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.

Thanks for any help.

Sounds fairly similar to the issue I mentioned here: Since Unity 2019.4.15, Resources.Load calls all fail until I rebuild

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.

1 Like

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.

Reading your link more carefully I just noticed you guys are using Zenject? Me too.

And my specific issue is that it fails to load the ProjectContext prefab from the Resources folder.

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’m not using Zenject, so that’s probably not directly related. It seems like more of an underlying issue.

Well, not to start a religious war or anything, but I found everything about Zenject to be hacky.

It seemed like a computer science construct that sounded really good on paper, but turned your project into a mess.

We used ZJ for about two years on a big project and it made tracking down initialization errors 10x times harder than without it.

Ultimately we abandoned it in favor of a traditional explicit order-of-initialization mechanism, and everything is so much better now.

And when ZJ was present, it caused all manner of weird lifecycle edge case things, which honestly sounds exactly like what you’re getting above.

2 Likes

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.

Also have this issue. Would be great to have a permanent fix.

Same here. Not using Zenject, but StrangeIOC. This is with Unity 2020. It fails to find a simple text asset file.

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.