Resources.Load not working

For one thing, never use Resources.Load() as T

Always use the Resources.Load<T>() form, in this case with a T of GameObject.

The reason: using Resources.Load("Foo") as GameObject might load a material or something else named “Foo” that is not a GameObject. Then when you cast-as to GameObject it will come out mysteriously null and cause errors.

More insidiously, if you have Foo.png and Foo.prefab, it is a 50/50 chance of what you’ll get, and it may vary from install to install. Don’t tempt fate.

If you use Resources.Load<GameObject>( "Foo") (or also Resources.Load<Texture2D>( "Foo")) you will get the correct object every time, assuming you meet the directory naming requirements (see docs).

For two things, make a fresh script, test the load function without all the network and callback stuff. Get that working first. Start with the Resources.Load() script documentation to ensure you are meeting 100% of the requirements. There are several very specific requirements.

5 Likes