transform.Find always returns null

I created a script to fire projectiles from the barrel of a weapon. Everything works fine until I try to get the grandchild that is the point where the projectile is created (weaponHardpointVector = transform.Find(“EnemyTankTurret/EnemyWeapon1”);:

  •  if(equippedWeapons[0] != null){*
  •  		while(i < equippedWeapons.Length){*
  •  		//Debug.Log ("Number of Equipped Weapons: " + equippedWeapons.Length);*

_ GameObject weapon = Instantiate(equippedWeapons*, transform.position, transform.rotation) as GameObject;_
//Debug.Log("Enemy Weapon Created: " +;_
weapon.transform.parent = transform;_
_ weaponBay = weapon.GetComponent();
Debug.Log("Weapon Bay 1: " + weapon.GetComponent());
weaponHardpointVector = transform.Find(“EnemyTankTurret/EnemyWeapon1”);
Debug.Log ("I Found : " + transform.Find (“EnemyTankTurret/EnemyWeapon1”));
Debug.Log ("Barrel Vector: " + weaponHardpointVector);

* }*
* }*
I keep getting:
> NullReferenceException: Object reference not set to an instance of an object
Enemy+c__Iterator3.MoveNext () (at Assets/Scripts/Enemy.cs:103)
Enemy:Update() (at Assets/Scripts/Enemy.cs:91)
I’ve checked the hierarchy and that all the spelling is correct. I’ve tried moving the object up to be a child instead of a grandchild and it still returns null. Am I using transform.Find() incorrectly?

Its tough to say without seeing your hierarchy and on which object the script is located. transform.Find() looks in everything thats part of that transform that the script is on. So if your script is on EnemyTankTurret, you would only need to put


Also remove the slash from the name of EnemyTankTurret, slashes in gameobject names makes Unity confused, as it looks for them to be indicators of parent children relationships, like folders. Unity - Scripting API: Transform.Find