Resources.LoadAll(); GameObject[] Array

Here is my question:

using UnityEngine;
using System.Collections;

public class Hajawack : MonoBehaviour {
	GameObject[] objMatToCompTo;
	// Use this for initialization
	void Start () {
		objMatToCompTo = Resources.LoadAll("(1)BlockPreFab", typeof(GameObject)) as GameObject[];
	}
	
	// Update is called once per frame
	void Update () {
		Debug.Log(objMatToCompTo[0].name);
	
	}
}

Debug.Log, instead of printing, gives me the error:

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

What should i do?

Assuming you have folder (1)BlockPreFab under Assets\Resources, then Resources.LoadAll probably works ok, but converting result messes things up. You can’t convert Object to GameObject. You have to do your casting differently, for example using LINQ:

objMatToCompTo = Resources.LoadAll("(1)BlockPreFab", typeof(GameObject))
    .Cast<GameObject>()
    .ToArray();

Additionally you need to add

using System.Linq;

on top of your script.