I cant get my files to load, Please help me

I cannot get past “Object Reference not sent to an instance of an object” When trying to load in assets dynamically.

Heres all the code I have

void Start()
{
    var sp = Resources.Load("Assets/Sprites/sprite_00.png") as Sprite;
    Debug.Log(sp.name);

}

This is returning a Null Reference Exception

 NullReferenceException: Object reference not set to an instance of an object

The path to the file im trying to load is Assets/Sprites/sprite_00.png

Ive tried loading it as a gameobject, or referencing different properties of the sprite, but I cannot get the sprite to load.

Im betting ive made some sort of beginner issue somewhere in here, please enlighten me.

yes well for a start you must create a folder called “Resources” in the assets folder

so it should look like “Assets/Resources/”

and then when you do resources.load you dont need to call for the assets path because its already implicit that the path is the resources folder

I have changed it to

 void Start()
   {
       var sp = Resources.Load("Sprites/sprite_00.png") as Sprite;
       Debug.Log(sp.name);    
   }

And I have placed the sprites folder in a Resources folder. Nothing has changed, code still doesn’t work.

Remove the extension (.png). This is because Resources loads “assets”, not files, the files per-se dont exist at runtime, just their asset representations.

From docs ( Unity - Scripting API: Resources.Load (unity3d.com)):

For example, a project may have Resources folders called Assets / Resources/ and Assets / Guns / Resources/ .
The path does not need to include Assets and Resources in the string, for example loading a GameObject at Assets / Guns / Resources / Shotgun.prefab would only require Shotgun as the path .
Also, if Assets / Resources / Guns / Missiles / PlasmaGun.prefab exists it can be loaded using Guns / Missiles / PlasmaGun as the path string.
If you have multiple Resources folders you cannot duplicate the use of an asset name.

Generally don’t guess when programming. Yes you can, but when something doesn’t work, recognize that you guessed at something and immediately check the documentation.

You really owe it to yourself to start with the docs for Resources.Load() which actually contains example code and shows precisely the two ways your line above is incorrect.

Additionally, you may wish to keep this in mind:

Always use Resources.Load<T>(), never use Resources.Load() as T

And the same goes for Resources.LoadAll<T>()

Generally you want to avoid writing code that is simply waiting to mysteriously fail simply by the future appearance of an identically-named file of a different type.

ALSO: Always put your resources in type-ish subfolders if you use Resources.LoadAll(). Here’s why:

As of this writing, if you use Resources.LoadAll<T>("foldername/");, Unity will load ALL FOUND ASSETS at that path into memory, then check each type and only return to you the ones that meet type T. But Unity will have already loaded all the assets it finds in that path, so expect massive performance problems if you don’t use subdirectories, even crashes due to running out of memory if you have a lot of assets there.