I’ve checked a while and I still can’t figure this out. My goal is to give my enemy a prefab gun and when the game starts, the options like where the tip of the gun is will auto-fill. It always returns null so it doesn’t auto-fill.
Public GameObject Pistol;
public Transform GunTip;
void Start()
{
Pistol = this.gameObject.transform.Find("Pistol").gameObject;
if (Pistol != null)
{
GunTip = Pistol.transform.Find("Tip").transform;
}
}
// other part of the script that works fine manually

I’ve also tried Pistol = transform.Find().gameObject;
The script is on the gameobject in blue.
Any help is appreciated.
Where and when do you create the Pistol?
Before the game starts. I just drag the prefab onto the enemy.
And which object is this script attached to?
So which thing is null? Pistol or GunTip?
Did some testing. I fixed the pistol by putting it in update. My new problem is I’m getting errors saying the object doesn’t exist. Which for some of the other enemies is true. How do I find if the object exist for each enemy?
Well there’s no reason really to be getting the GameObject just to get back to the transform:
public Transform Pistol;
public Transform GunTip;
void Start()
{
Pistol = transform.Find("Pistol");
if (Pistol != null)
{
GunTip = Pistol.transform.Find("Tip");
}
}
I did some more testing and I think start only does the first 3 lines of code. I moved my gun code to the top and it all works, but the code after it doesn’t.
void Start()
{
Pistol = transform.Find("Pistol");
AK = transform.Find("AK-47");
//Line 3 works
//Line 4 does not work
}
Do you have any errors in your console?
Yes, the fourth line is finding my Nav Mesh Agent and since it’s not finding it, I get a lot of errors. (New conclusion: I can’t use .Find() twice. only one line will work. Edited)