Resources.Load is always leading to NullReferenceException

Hello guys ! I’ve search all around the web and can’t find anything to help me …

I’m trying to load a prefab at runtime … but I’m always getting :

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

Here is my Assets folder :

107423-prefabs.png

And here is how I’m trying to load it at runtime :

    private void loadResources()
    {
        // Load prefabs

        // -- planet 1
        planetsRes[0] = Resources.Load("Prefabs/PRF_Planet1") as GameObject;

        // -- planet 2
        planetsRes[1] = Resources.Load("Prefabs/PRF_Planet2") as GameObject;

        // -- planet 3
        planetsRes[2] = Resources.Load("Prefabs/PRF_Planet3") as GameObject;

    }

Do you have any idea why I can’t access too my prefabs ?

PS : the full error I getting is :

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

That code shouldn’t cause a NullReferenceException even if it can’t find your resource.

What is “planetRes”?

Are you newing it up? My guess is that “planetRes” is what’s null.

Try:

planetRes = new GameObject[3];