Null Reference Exception on instantiated object's script.

Hello, I’m trying to get a script component from an instantiated object, but when I try to access any members from the script it gives me Null Reference Exception. The BlockBehaviour script is attached to the game object.

public GameObject block;
public GameObject gBlock;

	gBlock = (GameObject)Instantiate(block, this.transform.position, Quaternion.identity);
	
	if (gBlock){
		//Tell the DragCamera script that we are holding a block
		DragCamera.onBlock = true;
		
		//Get the block script
		//bb = (BlockBehaviour)gBlock.GetComponent<BlockBehaviour>();
	
		//Set alpha level to 0.6
		gBlock.GetComponent<BlockBehaviour>().setTransparent(0.6f);
		
	}

After quite long conversation, it looks that the part of the problem was initiating the variable inside Start() method. Changing this to Awake() was a step towards fixing the error.

Make sure that, that GameObject actually already has the script BlockBehaviour. If it is a prefab, then add the script before runtime. If it is just a random GameObject. Try adding the Script before trying to access it.