# Null Reference Exception ? :/

**URL:** https://discussions.unity.com/t/null-reference-exception/70099
**Category:** Questions & Answers
**Created:** [May 4, 2013, 8:11am UTC](https://discussions.unity.com/t/null-reference-exception/70099 "2013-05-04T08:11:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [May 4, 2013, 8:11am UTC](https://discussions.unity.com/t/null-reference-exception/70099/1 "2013-05-04T08:11:43Z")

</div>

UnityEngine.GameObject.GetComponent () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:27)  
xa.Start () (at Assets/Scripts/xa.cs:30)

I get this error when i go to run my game

Here is my code

```
using UnityEngine;
using System.Collections;

    public class xa : MonoBehaviour 
    {
    	public static Ball ball;
    	public static AudioManager audioManager;
    	public static ScoreManager scoreManager;
    	
    	public static Player1 player1;
    	public static Player2 player2;
    	//public static Player3 player3;
    	//public static Player4 player4;
    	
    	public static bool gameOver = false;
    	
    	// set to false if game is configured for CTF
    	public static bool letsPlayKeepaway = false; 
    	
    	// layers
    	public const int Team1Goal = 9;
    	public const int Team2Goal = 10;
    	
    	void Start()
    	{
    		// cache these so they can be accessed by other scripts
    		ball = GameObject.FindWithTag("Ball").GetComponent<Ball>();
    		scoreManager = gameObject.GetComponent<ScoreManager>();
    		audioManager = gameObject.GetComponent<AudioManager>();
    		player1 = GameObject.Find("Player1").GetComponent<Player1>();
    		player2 = GameObject.Find("Player2").GetComponent<Player2>();
    		//player3 = GameObject.Find("Player3").GetComponent<Player3>();
    		//player4 = GameObject.Find("Player4").GetComponent<Player4>();
    	}
    }

```

I dont know what i need to change or set ?  
If anyone has some advice?

---

<div class="post-metadata">

### Author: ![Chronos-L](https://avatars.discourse-cdn.com/v4/letter/c/e36b37/32.png) [@Chronos-L](https://discussions.unity.com/u/Chronos-L)
#### Post date: [May 4, 2013, 9:07am UTC](https://discussions.unity.com/t/null-reference-exception/70099/2 "2013-05-04T09:07:56Z")

</div>

“Player1” doesn’t exists in your scene, so `GameObject.Find("Player1")` returns a `null` and the `null` created the null-ref exception when you call `GetComponent< Player1 > ()`.

Side Note:  
Please format your code properly for your own convenience. I did it for you this once.
