I CANNOT understand what the problem is here. Won’t past the whole code, just the parts that matter and it seems to me like it should work. it’s a muzzle flash for a gun. one of many times I have used this exact same set up and they all work but for some reason I keep getting “Object reference not set to an instance of an object”. The first error being in the start function and then more for every time I actually settrigger or refer to the gameobject at all. Tried it with just the ani reference and this version also adding the gameObject itself, then making it public so I dragged it into the proper slot and unity still has no clue. The object is buried in the hierarchy of the actual sniper( ( like all enemy muzzleflashes that work) but even if I take it out and just lay it in the scene as a separate gameobject the code returns same errors. Driving me crazy!!! I see nothing different from this and the other guns that work - but “yes” all muzzleflashes have unique names so I can’t be confusing unity that way.
EDIT. fixed it just went back to the saved version with the working sniper and redid the grenade stuff and all is well. No clue what broke or why but the sniper scripts are EXACTLY the same. Fixed the situation in less than 20 minutes this way . wasted most of the day trying figure out why it broke rather than reverting. live and learn
Animator ani;
public GameObject sniperMuzzleFlash;
void Start()
{
sniperMuzzleFlash = GameObject.Find ("sniperMuzzleflash");
ani = GameObject.Find("sniperMuzzleflash").GetComponent <Animator> ();
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
ani.SetTrigger ("muzzleFlash");