Null Reference Problem Code+pic (SOLVED)

How can this give me a null reference problem:

function Update () {
	var AC : AttackComponent = GetComponent(AttackComponent);
	AC.findNearEnemy();
}

The AttackComponent script is already put on my gameobject which is called “smallUnit”:

Moderator Note: Remember that you can also edit your questions when you need to give more details. I thought the pictures would stay on the server after I deleted the answer. They didn't. -Jamora

EDIT:

First of all…I am so amazed of this community, wow thanks for the replies!

Back to topic:
My gameobject has 3 important scripts on it:

  • AttackComponent(instantiated as AC)
  • MoveComponent(instantiated as MC)
  • UnitController(instantiated as UC).

The last stated is the “main” script of the gameobject which works as a bridge between the two first stated, so they can call different functions through the UnitController.
Anyway as you can see, the three scripts is attatched to the gameobject:

alt text

Broken down to this scenario, my UnitController has this:

var AC	:AttackComponent;
var MC	:MoveComponent;

function Awake(){
	AC	= GetComponent(AttackComponent);
	MC	= GetComponent(MoveComponent);
}

function Update () {
	AC.findNearEnemy();
}

My AttackComponent has (broken down for this scenario) this:

    var UC : UnitController;
    
    function Awake(){
    	UC = GetComponent(UnitController);
    }
    function findNearEnemy(){
    	//nothing yet, just a dummy function 		
    }

I think it is a problem with the AC.findNearEnemy(). My MC in UnitController doesn’t give me any problems, so I am on unknown ground for my sake :frowning:
The error message i get:

alt text

Drag the relevant objects in to the places in the script where you see ‘None’

I FOUND IT…I FOUND IT…
Sorry for taking anyones time…after some time, I decided to look at the other gameobjects I have in the scene. And here I found, that I have by a mistake applied the UnitController to a gameobject with no such need, and therefore when the script repeatedly called the AC.findEnemyUnit() on an object that didnt have an AttackComponent script on it…it puked the error…
Sorry for anything, and thanks for everything :slight_smile: