NullReferenceException: Object reference not set to an instance of an object? (102048)

Object A instantiates Object B on KeyPress. This script is attached to Object B.

	private GameObject crowd;
	void Start()
	{
		crowd = GameObject.Find ("Crowd(Clone)");
	}

	void Update()
		{
			if (!GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerDamage>().invulnerable)
			{
				if (gameObject.renderer.bounds.Intersects(crowd.renderer.bounds)) {
					// Do some stuff
				}
			}
		}
  • NullReferenceException: Object reference not set to an instance of an object
    DestroyRadius.Update ()

right, as with all NRE you’re trying to access something that doesn’t exist

So either,

  1. there’s not an object tagged “Player”
  2. There is, but it doesn’t have a PlayerDamage script attached*
  3. It does, but that script doesn’t have a .invulnerable().
  4. Or finally, the current gameObject doesn’t have a renderer

(*alternatively, there might be more than one object tagged player and the one that its finding does’t have the PlayerDamageScript)