Resources.Load failing in 2020.2

Wasn’t sure the best place to post this.

We have been using RuntimeInitializeLoadType.BeforeSceneLoad to load and instantiate a small handful of prefabs that are always present and only loaded once.

In 2020.2 Resources.Load sporadically returns null values.

Is there a better hook for loading prefabs that only need to be loaded once for the life of the game, and will work regardless of what the initial scene being loaded is? That last criteria is why we were using this hook.

1 Like

Having the same issue here.

Resouces.Load always returns Null. LoadAll howerver, also returns empty arrays.

Don’t think this is an Addressables issue. I’m going to move this thread over to the Scripting forums.

Always use the templated version of Resources.Load<>();

GameObject prefab = Resources.Load<GameObject>( "MyModel");

The reason:

If you just say:

GameObject prefab = Resources.Load( "MyModel") as GameObject;

And you ALSO have a Material in there called MyModel.mat, there is a 50/50 chance you will get the GameObject. If there is also a Texture in there called MyModel.png, your odds of getting it right go down to 33%… and it might fail the next time you reimport.

If you get the Material or Texture, that object will fail the cast to GameObject (obviously) and you’ll get a null.

In short, NEVER use Resources.Load();… I wish Unity would just remove it somehow.

ONLY use Resources.Load<T>();

1 Like